Koozali.org: home of the SME Server

Problems with php, SME server and me

noidea

Problems with php, SME server and me
« on: June 05, 2006, 09:30:23 AM »
Hi Noidea again!!!  I am current trying to connect to MySql 5 with php code this is what I have typed
<?php

 // Database Specific information
 DEFINE ('DB_USER', 'MyUser')
 DEFINE ('DB_PASSWORD', 'MyPass')
 DEFINE ('DB_HOST', 'localhost')
 DEFINE ('DB_NAME', 'MyDB')
 
 // Connect to MySQL and select database:
 $dbc = mysqli_connect(DB_HOST, DB_USR, DB_PASSWORD, DB_NAME)
 
 ?>
When I run this code I get a blank page which if everything is correct is what I should get but if I change the values of say MyUser to an incorrect value I still get a blank page.  Is this code right? Do I have to activate something in MySQL or SME?  I used help from this forum and connect to MYSQL with navicat so I know that is working.

I am just confused it is hard being a newbie with noidea.

Thanks in advance

Paul

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: Problems with php, SME server and me
« Reply #1 on: June 05, 2006, 11:38:01 AM »
Quote from: "noidea"
Hi Noidea again!!!  I am current trying to connect to MySql 5 with php code this is what I have typed
<?php

 // Database Specific information
 DEFINE ('DB_USER', 'MyUser')
 DEFINE ('DB_PASSWORD', 'MyPass')
 DEFINE ('DB_HOST', 'localhost')
 DEFINE ('DB_NAME', 'MyDB')
 
 // Connect to MySQL and select database:
 $dbc = mysqli_connect(DB_HOST, DB_USR, DB_PASSWORD, DB_NAME)
 
 ?>
When I run this code I get a blank page which if everything is correct is what I should get but if I change the values of say MyUser to an incorrect value I still get a blank page.  Is this code right? Do I have to activate something in MySQL or SME?  I used help from this forum and connect to MYSQL with navicat so I know that is working.

I am just confused it is hard being a newbie with noidea.

Thanks in advance

Paul
This problem has not much to do with SME Server. SME Server is not configured as a machine to design your code on, therefore errors are not reported (to the user) and you will receive a blank page. You can change the php settings in the php.ini templates, browse the httpd error log or try to neatly handle errors in your own code (the latter is the best option as good code always has ways to handle errors properly).

There are a few mistakes in your sourcecode anyhow:
  • any line in php should be terminated by a semicolon.
  • If you define DB_USER and try to connect using an undefined DB_USR value it will certainly not work.
My advice is to first find a good tutorial for php and mysql using google and find a newsgroup or furm for php to ask php related questions, for instance:
Code: [Select]
<?php

  
// Database Specific information
  
DEFINE &#40;'DB_USER', 'MyUser'&#41;;
  
DEFINE &#40;'DB_PASSWORD', 'MyPass'&#41;;
  
DEFINE &#40;'DB_HOST', 'localhost'&#41;;
  
DEFINE &#40;'DB_NAME', 'MyDB'&#41;;
 
  // Connect to MySQL and select database&#58;
  
$dbc mysqli_connect&#40;DB_HOST, DB_USER, DB_PASSWORD, DB_NAME&#41; or die&#40;'Could not connect&#58;' . mysql_error&#40;&#41;&#41;;
?>

Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline mike_mattos

  • *
  • 313
  • +0/-0
Problems with php, SME server and me
« Reply #2 on: June 05, 2006, 01:54:04 PM »
if you

# cd /etc/e-smith/templates/etc/php.ini

you can back up the file 30ErrorHandling to a different directory ( don't make a copy in this directory!)

After making  a backup, edit 30ErrorHandling, changing the various lines to On as you see fit.

After restarting your conputer, your php session should report & log errors

Note: This is based on SME6 with MySql4, I'm trusting it works on SME& & MySQL5 or else I'm in trouble when I restart my own system!
...

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Problems with php, SME server and me
« Reply #3 on: June 05, 2006, 02:03:57 PM »
Quote from: "mike_mattos"
if you

# cd /etc/e-smith/templates/etc/php.ini

you can back up the file 30ErrorHandling to a different directory ( don't make a copy in this directory!)

After making  a backup, edit 30ErrorHandling, changing the various lines to On as you see fit.

After restarting your conputer, your php session should report & log errors

Note: This is based on SME6 with MySql4, I'm trusting it works on SME& & MySQL5 or else I'm in trouble when I restart my own system!


That is exactly what you should not do... for this we have the templating system. Never modify the configuration file direclty, nor the template sections in the /etc/e-smith/templates directory. Instead make a copy of the template you want to modify in the corresponding directory in the /etc/e-smith/templates-custom/ directory and make your modifications there.
Code: [Select]
mkdir -p /etc/e-smith/templates-custom/etc/php.ini
cp /etc/e-smith/templates/etc/php.ini/30ErrorHandling /etc/e-smith/templates-custom/etc/php.ini/
After making your modifications to the copied fragment expand the template again:
Code: [Select]
expand-template /path/to/config/fileSo to expand the php.ini file issue the following command:
Code: [Select]
expand-template /etc/php.iniTo load these changes restart thee httpd daemon (as php is a module of httpd)
Code: [Select]
/etc/rc7.d/S86httpd-e-smith sigusr1
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

noidea

Problems with php, SME server and me
« Reply #4 on: June 06, 2006, 03:17:16 AM »
Thanks for you advice.  After reading some of the other forums is it correct that SME 7 doesn't support php 5?.  The tutorial I am using is all in php 5, should I try to upgrade SME to php 5 or should I leave as is and get another tutorial?

Or am I barking up the wrong tree does SME 7 support PHP 5?

Thanks
Paul

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Problems with php, SME server and me
« Reply #5 on: June 06, 2006, 05:05:17 PM »
Quote from: "noidea"
Thanks for you advice.  After reading some of the other forums is it correct that SME 7 doesn't support php 5?.  The tutorial I am using is all in php 5, should I try to upgrade SME to php 5 or should I leave as is and get another tutorial?

Or am I barking up the wrong tree does SME 7 support PHP 5?

Thanks
Paul
No SME Server does not support PHP 5, as they only use the CentOS stock RPM's. As they are on PHP 4 and will be for a while probably, SME won't support PHP5 for the time being. Trying to install PHP5 will not be an easy one, I believe that a few users tried and broke their system. Do you really need PHP5?
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

noidea

Problems with php, SME server and me
« Reply #6 on: June 07, 2006, 08:23:18 AM »
Thanks for all your help.  No I don't need PHP 5 I just had a book on it but I went and exchanged if for one on PHP 4.  Just wrote my very first bit of code,  so thank you for helping me get there.

Regards
Paul