Home |  MySQL Buzz |  FAQ |  Feeds |  Submit your blog feed |  Feedback |  Archive |  Aggregate feed RSS 2.0 English Deutsch Español Français Italiano 日本語 Русский Português 中文
Showing entries 1 to 30 of 30

Displaying posts with tag: PHP/MySQL (reset)

How To – Configure MySQL to Use UTF-8
+1 Vote Up -1Vote Down

Background Knowledge


Using the character set UTF-8 allows for the use of any language, can represent every character in the Unicode character set and is backward compatibility with ASCII. Not to mention is can handle any platform and be sent through many different systems without corruption. With such advantages this is why so many are making the switch.

The following instructions were done on Debian Squeeze v6.04 AMD64 operating system using MySQL v14.14 Distrib 5.1.61.

Solution – Server Configuration


At present MySQL is configured by default to use “latin1″ character set. Here’s how to change MySQL configuration to use UTF-8 character set and collation.

  • Check MySQL’s current configuration, run the following two SQL statements.
    1
    2
    
    SHOW VARIABLES LIKE '%collation%'; 
    SHOW
  •   [Read more...]
    How To – Fix MySQL Option Without Preceding Group
    +0 Vote Up -0Vote Down

    Background Knowledge


    You try starting, stopping or connecting to MySQL and receive the following error, “Error: Found option without preceding group in config file: /etc/mysql/conf.d/char_collation_set.cnf at line: 1″. The error message my vary but comes to the same issue. MySQL may not start or might experience connectivity issues.

    This issue was experienced on Debian Squeeze v6.04 AMD64 system with MySQL v14.14 Distrib 5.1.61.

    Solution


    This issue is caused by a improperly formatted MySQL configuration file(s) and refers to one missing the group heading (e.g. [mysqld], [mysqld_safe], etc.).

    Source:   [Read more...]

    Example of a Basic MSSQL Query using PHP
    +0 Vote Up -2Vote Down

    An example of a basic MSSQL (Microsoft SQL Server/SQL Server Express) query using PHP.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    $szQry = "SELECT column1, column2 FROM foo";
    $szDBConn = mssql_connect("host","username","password");
    mssql_select_db("database_name", $szDBConn);
    $saResults = mssql_query($szQry, $szDBConn);
    while($obResults = mssql_fetch_row($saResults))
    {
       echo $obResults[0]." ".$obResults[1];
    }
    mssql_close($szDBConn);

    Comments/description of Example

    Line #1 SQL statement that will be sent to the MySQL database server. Line #2 MSSQL database login credentilas; host (127.0.0.1), username and password. The “host” is the server name or IP address of your database server. If your host has multiple  [Read more...]
    PHP – Upgrading v5.2.5 to v5.2.8
    +0 Vote Up -0Vote Down

    Background Knowledge


    The following is the process I took to upgrade a web server with PHP v5.2.5 to PHP v5.2.8 running on OpenBSD. PEAR is already installed on this system and up to date. I wasn’t sure if I should exclude PEAR at install or not so therefore did not tell the configurator to exclude PEAR at install.

    Installation Process


  • Download the latest stable PHP release from command prompt # wget http://ca.php.net/get/php-5.2.8.tar.gz/from/a/mirror
  • # tar -zxvf php-5.2.8.tar.gz
  • ./configure –with-mysql=/usr/local –with-mssql=/usr/local –with-apxs –with-zlib-dir=/usr/lib –with-config-file-path=/var/www/conf
  •   [Read more...]
    Pear::Date Returned Timezone is Wrong
    +0 Vote Up -0Vote Down

    Background Knowledge


    I’m trying to determine the difference in minutes between two timestamps. I’m using Pear::Date to do this. The issue comes into play when I noticed that the wrong timezone was being used by Pear::Date, UTC. If I do not use Pear::Date the timezone is set correctly.

    I have tried using date_default_timezone_set() and it does set the timezone back, however I feel this shouldn’t be necessary as the default timezone should be used. I have been using date_default_timezone_get() to determine what timezone is being used.

    It’s my understanding that Pear::Date uses UTC when it is unable to determine the default timezone. As far as I know I

      [Read more...]
    Using short if statement in programming
    +0 Vote Up -0Vote Down

    In many programing languages it is possible to shorten if statements using what’s called the ternary operator. It is sometimes referred as the “one line if statement” or the “short if statement”. This can help at times to produce cleaner code, however use this operator wisely as it is not always best to be used for more complicated statements.

    PHP Example of an if statement


    1
    2
    3
    4
    5
    6
    7
    8
    
    if($nFoo > 0)
    {
       echo "I'm at the work.";
    }
    else
    {
       echo "I'm at home.";
    }

    PHP Example using the ternary operator


    1
    
    echo $nFoo > 0 ? "I'm at the work." : "I'm at home.";

    The expression (expr1) ? (expr2) : (expr3) evaluates to expr2 if

      [Read more...]
    How To - Remove Leading Zeros
    +0 Vote Up -0Vote Down

    Solutions

    Using PHP function intval().

    Code example: echo intval(”05″);
    Returned value: 5

    Using PHP function ltrim().

    Code example: echo ltrim(”005″,”0″);
    Returned value: 5

    ShareThis

    How To - Convert MySQL Timestamp/Datetime to Unix Timestamp
    +0 Vote Up -0Vote Down

    Background Knowledge


    Since MySQL v4.1 timestamp and datetime data types are formatted “YYYY-MM-DD HH:MM:SS”. Prior to MySQL v4.1 the timestamp was formatted as YYYYMMDDHHMMSS” and datetime formatted as “YYYY-MM-DD HH:MM:SS”. Refer to MySQL Reference Manual for further details.

    The Unix timestamp differs from MySQL. Unix’s timestamp is a integer value of seconds since January 1, 1970. For further explanation of Unix timestamps refer to Wikiepedia or UnixTimestamp.com.

    Solutions


    In MySQL you can use

      [Read more...]
    French Characters Not Rendering Correctly
    +0 Vote Up -0Vote Down

    Background Knowledge


    The MySQL database (http://www.mysql.com/) v4.0.23 is using the default character set of “Latin1″. When the database was created I had no knowledge of character sets other wise it would have been “UTF-8″.
    The web pages are using a character set of “UTF-8″.

    Problem


    Data being queried from a MySQL database (http://www.mysql.com/) that contains French accent characters will not render correctly in the browser even after applying PHP htmlentities().

    Example code: $string = htmlentities($string , ENT_QUOTES, “UTF-8″);

    Solution


    The queried data from the database was inputted using the


      [Read more...]
    PHP Calendar Functions Error
    +0 Vote Up -0Vote Down

    I was trying to use the PHP calendar API and immediately received this error message, “Fatal error: Call to undefined function cal_days_in_month()”. This error message means PHP was not compiled with the calendar extension.

    Solution


    The only solution to this error message and other similar error messages relating to the PHP calendar API requires PHP to be compiled with the calendar extension by adding “–enable-calendar” to the “configure command” as stated in the PHP documentation on the Calendar functions page.

    How to Tell if the Calendar Extension is Installed


    You can verify weather or not the PHP Calendar extension was compiled at install by using the phpinfo() function. When viewing the output of phpinfo() look under “Configure

      [Read more...]
    PHP Free Chat - Joining Chat Email Notification
    +0 Vote Up -0Vote Down

    I recently upgraded an install of PHP Free Chat to that latest version of 1.0 Final. However it was still lacking a feature to notify individual(s) that someone has joined the chat if they were not already in the chat application to begin with. I came across a posting explaining how to achieve this in PHP Free Chat at PHP Free Chat Forum. After a little reading and discussion I was able to implement the feature.

    Here’s my modified version for the solution based on the forum posting. The pfcmail() function can be made to be way more versatile for any use, however for my use it was made to be simple and produce properly formated email messages.

    Solution


  • Create a new PHP file called pfcmail.php with the following
  •   [Read more...]
    Default Timezone in PHP, Not Working?
    +0 Vote Up -0Vote Down

    Since I started using PHP 5.x.x I started to experience incorrect time reported back through PHP using for example date(). I checked phpinfo() and found out that the default timezone was detected as America/Chicago. This was not the case as the server was configured for Canada/Saskatchewan (CST). I found out that I ended up having to directly set my timezone in php.ini file. I put the following in my php.ini file, then restarted Apache and the problem was resolved.

    date.timezone = “Canada/Saskatchewan”

    I’m not sure if this is a bug in PHP not detecting the timezone correctly. I tried searching through known

      [Read more...]
    Common Mistake - Echoing an Array
    +0 Vote Up -0Vote Down

    I’m sure most would agree when one does a programming mistake they are a lot of times trivial mistakes. However when one stares at the code for long periods of time we seem to go blind and then in the process of frustration loose all logically thinking as to what could be causing the problem. Here is one such problem with arrays.

  • Problem
  • The value of the Array is not rendering. Instead you see array[0].
  • Solution
  • Remove your single or double quotes around the variable representing the array. When one places single or double quotes around the array you are causing it to be treated as literal.

    ShareThis

    PHP - Populate HTML Select Element
    +0 Vote Up -0Vote Down

    There is many ways to populate vales into a HTML select element. Here is one example I’ve come up with.

    PHP Code Example

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
    <select size="1" name="szFooBar[]" multiple="multiple">
    < ?php
    $i=0;
    while($obResults = mysql_fetch_row($saResults))
    {
        if ($_POST['szFooBar'] == $obResults[0])
        { $szSelectedValue[$i] = " selected=\"selected\""; }
        else { $szSelectedValue[$i] = ""; }
     
        printf("<option value=\"%s\"%s>%s\n",$obResults[0], $szSelectedValue[$i], $obResults[1]);
        $i++;
    }
    ?>							
    </select>

      [Read more...]
    PHP/MySQL Query Example
    +0 Vote Up -0Vote Down

    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);

    ShareThis

    MySQL Lost connection to MySQL server during query
    +0 Vote Up -0Vote Down

    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 (http://www.mysql.com/) through PHP. It kept returning back to me “Lost connection to MySQL server during query”. Right away I went to my PHP, MySQL (http://www.mysql.com/) 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

      [Read more...]
    PHP/MySQL Query Example
    +0 Vote Up -0Vote Down

    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
    +0 Vote Up -0Vote Down

    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 (http://www.mysql.com/) through PHP. It kept returning back to me “Lost connection to MySQL server during query”. Right away I went to my PHP, MySQL (http://www.mysql.com/) 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

      [Read more...]
    How to Install PHP from Source
    +0 Vote Up -0Vote Down

    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





      [Read more...]
    Midgard/PHP CLI Segmentation Fault
    +0 Vote Up -0Vote Down

    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

    ShareThis

    Midgard CMS - PEAR Install - Segmentation fault
    +0 Vote Up -0Vote Down

    If you are experiencing “segmentation faultâ€

    PEAR Mail/Mail_Mime Package Error
    +0 Vote Up -0Vote Down

    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â€

    Apache Warning - MySQL Lib Size Mismatch Solution
    +0 Vote Up -0Vote Down

    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




      [Read more...]
    How to Install PHP from Source
    +0 Vote Up -0Vote Down

    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





      [Read more...]
    Midgard/PHP CLI Segmentation Fault
    +0 Vote Up -0Vote Down

    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
    +0 Vote Up -0Vote Down

    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
    +0 Vote Up -0Vote Down

    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
    +0 Vote Up -0Vote Down

    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




      [Read more...]
    PEAR: Command Not Found
    +0 Vote Up -0Vote Down

    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

      [Read more...]
    PEAR: Command Not Found
    +0 Vote Up -0Vote Down

    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

      [Read more...]
    Showing entries 1 to 30 of 30

    Planet MySQL © 1995, 2014, Oracle Corporation and/or its affiliates   Legal Policies | Your Privacy Rights | Terms of Use

    Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.