Binary Expressions

« Previous Page

2005-8-9

PHP/MySQL Query Example

Filed under: — Adam @ 3:25 pm

A basic MySQL query using PHP with commenting marked with //.

// SQL statement that will be sent to the MySQL database server.
$szQry = “SELECT column1, column2 FROM foo”;

// MySQL database login credentilas; host (127.0.0.1), username and password.
$szDBConn = mysql_connect(”host”,”username”,”password”);

// Select database using the login credentials provided above.
mysql_select_db(”database_name”, $szDBConn);

// Send SQL statement to database.
$saResults = mysql_query($szQry, $szDBConn);

// Fetch results retured back from the SQL statement.
$obResults = mysql_fetch_row($saResults);

MySQL Lost connection to MySQL server during query

Filed under: — Adam @ 12:41 pm

For more than 3 hours I’ve been trying to find a solution to the error I kept receiving when doing a basic query to MySQL through PHP. It kept returning back to me “Lost connection to MySQL server during query”. Right away I went to my PHP, MySQL and Apache logs to find more information. I came back with nothing more than the error message I already received. So as I usually do off I went to Google and IRC for some help. Neither were leading into any direction to a solution. Even after finding the MySQL documentation talking about the “Lost Connection” or “server has gone away” error I didn’t find a solution. I started talking to dhartmei on EFNet in the #OpenBSD channel for some assistance. He stepped me through doing the following at the command prompt.

# nc -v 127.0.0.1 3306
Connection to 127.0.0.1 3306 port [tcp/mysql] succeeded!
Host ‘localhost.domain.com’ is not allowed to connect to this MySQL

# netstat -an | grep 3306
tcp 0 0 *.3306 *.* LISTEN

# mysql -h 127.0.0.1 -u username -p database
Enter password:
ERROR 2013: Lost connection to MySQL server during query

This determined that port 3306 was listening for connections however localhost/127.0.0.1 returned an error message of “Host ‘localhost’ is not allowed to connect to this MySQL”. If you haven’t caught on already this means I forgot to set MySQL permissions correctly for the user. Remember that localhost and 127.0.0.1 is different according to MySQL permissions.

A quick GRANT (i.e. grant all ON database.table TO username@localhost identified by ‘password-here’) command in MySQL resolved the problem.

2005-7-20

How to Install PHP from Source

Filed under: — Adam @ 2:01 pm

This installation example for Unix/Linux installs dependency support for Midgard CMS. Make sure Expat, zlib (comes with OpenBSD) and iconv are installed before proceeding. I have added additional configuration for MySQL (so the correct MySQL libraries are used), Microsoft SQL Server, apxs, XML, exif, dba and mbstring. Refer to the PHP configurator for details (# ./configure –help).

# ./configure –with-mysql=/usr/local –with-mssql=/usr/local –with-apxs –with-xml –with-zlib-dir=/usr/lib –with-expat –with-config-file-path=/var/www/conf –with-iconv=/usr/local/bin/iconv -–with-exif –-with-dba –-with-mbstring
# make
# make install
# make clean
# cp php.ini-recommended /var/www/conf/php.ini

Review/edit /var/www/conf/php.ini (path may vary) file to match your requirements. To meet the requirements of Midgard CMS you will require to do the following.

Add extension=midgard.so into your php.ini file.
Add the extensions path to extension_dir. Type “php-config –extension-dir”. Place the returned path into your php.ini file.
Ensure the file_uploads=on.
Ensure the short_open_tag=on.

Midgard/PHP CLI Segmentation Fault

Filed under: — Adam @ 1:43 pm

Midgard CMS will crash PHP CLI if its loaded in the global php.ini. Add PHP settings to your Apache HTTP Server configuration file /var/www/conf/httpd.conf (path may vary). Put the below PHP settings into your httpd.conf file. This may also go into your Midgard httpd.conf if you want. Make sure to restart your Apache HTTP Server so configuration changes take affect.

php_value extension midgard.so
php_value register_globals 1

Midgard CMS - PEAR Install - Segmentation fault

Filed under: — Adam @ 1:34 pm

If you are experiencing “segmentation fault” when trying to do a PEAR package install on a system using Midgard CMS, do the following.

  • Comment out “extension=midgard.so” line in php.ini.
  • Restart Apache HTTP Server.
  • Re-run Pear package install (i.e. pear install Mail).
  • Uncomment out “extension=midgard.so” line in php.ini.
  • Restart Apache HTTP Server.

PEAR Mail/Mail_Mime Package Error

Filed under: — Adam @ 1:28 pm

If you experience the following error that refers to mailtemplate or mailmime, this means you don’t have PEAR Mail or PEAR Mail_mime package installed. For example after you have downloaded the PEAR package to install PEAR Mail package type at the shell prompt without quotes “pear install Mail”.

Example of error messages
Warning: main(Mail.php): failed to open stream: No such file or directory in
/usr/share/pear/midcom/lib/midcom/helper/mailtemplate.php on line 17

Fatal error: main(): Failed opening required ‘Mail.php’
(include_path=’.:/usr/local/share/php/pear’) in
/usr/share/pear/midcom/lib/midcom/helper/mailtemplate.php on line 17

Apache Warning - MySQL Lib Size Mismatch Solution

Filed under: — Adam @ 11:26 am

I was having some problems with my web site so I went off to check my Apache HTTPD error_log and found three warning messages logged.

Apache HTTPD error_log
/usr/sbin/httpd:/usr/lib/apache/modules/libphp4.so: /usr/local/lib/libmysqlclient.so.12.0 : WARNING: symbol(client_errors) size mismatch, relink your program
/usr/sbin/httpd:/usr/lib/apache/modules/libphp4.so: /usr/local/lib/libmysqlclient.so.12.0 : WARNING: symbol(default_directories) size mismatch, relink your program
/usr/sbin/httpd:/usr/lib/apache/modules/libphp4.so: /usr/local/lib/libmysqlclient.so.12.0 : WARNING: symbol(globerrs) size mismatch, relink your program

After some time of research and with no solution, I decided to mention the problem in Midgard IRC channel. With Piotras comment, I quote “TheWarden: php was compiled with different version of mysql libraries”. So with that said off I went to re-install PHP v4.3.11 but this time configure it with –with-mysql=/usr/local so the correct MySQL libraries would be used. If –with-mysql is not used PHP will use it’s own built in MySQL libraries. I double checked my Apache HTTPD error_log and now the warnings are no longer present.

2005-7-11

PEAR: Command Not Found

Filed under: — Adam @ 11:32 am

I recently installed PHP 4.3.11 from source (due to configuration requirements) on to an OpenBSD i386 v3.7 server. The installation went perfectly as it has many times before, however I found out that the PEAR script was not installed (normally in /usr/local/bin). I discovered this when trying to install some pear packages doing “pear install packagename”. I get a returned error of “-bash: pear: command not found”. I tried locating the PEAR script using “find / -name pear” and “/usr/libexec/locate.updatedb” then “locate -i pear”. The result came up empty with no PEAR script in the returned results. I double checked the PEAR documents, PHP documents and ./configure all three places stated PEAR is installed by default unless a parameter is provided at configure with –without-pear. I’m still not aware as to why the PEAR script was not installed however with help by SmallOne of #midgard I was able to resolve the problem manually. Here’s how it was resolved at the shell prompt.

  • # cp pear.sh /usr/local/bin/pear
  • # chmod 755 /usr/local/bin/pear

If anyone knows how the PEAR script could not have been installed please let me know, thanks.

« Previous Page

Take back your mailbox - CAUCE.org

Powered By Wordpress PHP: Hypertext Preprocessor MySQL Powered Download Juice, the cross-platform podcast receiver
Proud To Be Canadian Get Firefox Valid XHTML Valid CSS
<NO>OOXML Logo


27 queries. 0.356 seconds.
Copyright © 2004 - 2005 by Adam Douglas