| | |
Connecting to MySQL with PHP
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
I have MySQL running such that I can open a client command line and log on and make databases, tables, etc.
I wanted to do some AJAX. Doing AJAX with ASP, SQL Server, etc is not advisable since both places where I am hosting my websites do not use the Microsoft products. So I am forced to do my development with PHP and MySQL.
I just about have everything set up. I have set up IIS so that I can go to my localhost and I can test out web pages. I have PHP installed so that I can pull up the PHP setting pages.
The problem occurs when I try to bring up the MySQL database in PHP. I use this very simple PHP command:
<?php
$con = mysql_connect('localhost', 'testuser', 'testpassword');
?>
When I try to connect to the mysql database through PHP, I get this error:
Click Here
I figure the problem must be in the settings that are in the php.ini. But it seems that my php.ini is set up for MySQL although it is not mentioned in the output when I query the phpinfo page with this code
<?php phpinfo(); ?>
Here is the result from this:
Click Here
I wanted to do some AJAX. Doing AJAX with ASP, SQL Server, etc is not advisable since both places where I am hosting my websites do not use the Microsoft products. So I am forced to do my development with PHP and MySQL.
I just about have everything set up. I have set up IIS so that I can go to my localhost and I can test out web pages. I have PHP installed so that I can pull up the PHP setting pages.
The problem occurs when I try to bring up the MySQL database in PHP. I use this very simple PHP command:
<?php
$con = mysql_connect('localhost', 'testuser', 'testpassword');
?>
When I try to connect to the mysql database through PHP, I get this error:
Click Here
I figure the problem must be in the settings that are in the php.ini. But it seems that my php.ini is set up for MySQL although it is not mentioned in the output when I query the phpinfo page with this code
<?php phpinfo(); ?>
Here is the result from this:
Click Here
So, MySQL is no longer enabled by default, so the php_mysql.dll DLL must be enabled inside of php.ini. How is this done? I searched php.ini and I did not find php_mysql.dll.
In my php.ini file I found this section under [MySQL]
[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent = On
; Maximum number of persistent links. -1 means no limit.
mysql.max_persistent = -1
; Maximum number of links (persistent + non-persistent). -1 means no limit.
mysql.max_links = -1
; Default port number for mysql_connect(). If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
; at MYSQL_PORT.
mysql.default_port =
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =
; Default host for mysql_connect() (doesn't apply in safe mode).
mysql.default_host =
; Default user for mysql_connect() (doesn't apply in safe mode).
mysql.default_user =
; Default password for mysql_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password")
; and reveal this password! And of course, any users with read access to this
; file will be able to reveal the password as well.
mysql.default_password =
; Maximum time (in seconds) for connect timeout. -1 means no limit
mysql.connect_timeout = 60
; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
; SQL-Errors will be displayed.
mysql.trace_mode = Off
In my php.ini file I found this section under [MySQL]
[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent = On
; Maximum number of persistent links. -1 means no limit.
mysql.max_persistent = -1
; Maximum number of links (persistent + non-persistent). -1 means no limit.
mysql.max_links = -1
; Default port number for mysql_connect(). If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
; at MYSQL_PORT.
mysql.default_port =
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =
; Default host for mysql_connect() (doesn't apply in safe mode).
mysql.default_host =
; Default user for mysql_connect() (doesn't apply in safe mode).
mysql.default_user =
; Default password for mysql_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password")
; and reveal this password! And of course, any users with read access to this
; file will be able to reveal the password as well.
mysql.default_password =
; Maximum time (in seconds) for connect timeout. -1 means no limit
mysql.connect_timeout = 60
; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
; SQL-Errors will be displayed.
mysql.trace_mode = Off
I went back and redid the php installation from scratch and did the extra steps you mentioned. Now it works.
Well, I spoke to soon. Now I get a different kind of error.
pritaeas, I have added these two lines to PHP.ini :
extension=php_mysql.dll
extension_dir="/ext"
I have done all the steps in http://nl.php.net/manual/en/mysql.installation.php
to enable mysql with php. I have included c:\php in the system path. I have added the removed the semi colon on extension=php_mysql.dll in php.ini I have even copied the libraries into the c:\windows\system32 directories just to be sure.
But when I run a php script with this <?php phpinfo(); ?> from a php file, the result does not mention mysql.
The new problem I have is when I run a php file with
$con = mysql_connect('localhost', 'testuser', 'testpassword') or die("Could not connect");
The error I get in my browser says:
Fatal error: Call to undefined function mysql_connect() in C:\inetpub\wwwroot\getuser.php
pritaeas, I have added these two lines to PHP.ini :
extension=php_mysql.dll
extension_dir="/ext"
I have done all the steps in http://nl.php.net/manual/en/mysql.installation.php
to enable mysql with php. I have included c:\php in the system path. I have added the removed the semi colon on extension=php_mysql.dll in php.ini I have even copied the libraries into the c:\windows\system32 directories just to be sure.
But when I run a php script with this <?php phpinfo(); ?> from a php file, the result does not mention mysql.
The new problem I have is when I run a php file with
$con = mysql_connect('localhost', 'testuser', 'testpassword') or die("Could not connect");
The error I get in my browser says:
Fatal error: Call to undefined function mysql_connect() in C:\inetpub\wwwroot\getuser.php
Last edited by complete; Jul 17th, 2009 at 7:13 pm.
•
•
Join Date: Aug 2009
Posts: 2
Reputation:
Solved Threads: 0
Hi Experts,
I am getting this error message, "Error connecting to mysql"
whenever i am running the below scripts:
I've just set-up everything and still getting such error...
By the way, I am using Windows Vista ans IIS 7.0, Could you please help me? suggestions please, recommendations...
I am getting this error message, "Error connecting to mysql"
whenever i am running the below scripts:
php Syntax (Toggle Plain Text)
<?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'password'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'petstore'; mysql_select_db($dbname); ?>
I've just set-up everything and still getting such error...
By the way, I am using Windows Vista ans IIS 7.0, Could you please help me? suggestions please, recommendations...
Last edited by peter_budo; Aug 17th, 2009 at 4:45 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
![]() |
Similar Threads
- having trouble in connecting mysql with php (PHP)
- Connecting to MS Access with PHP (PHP)
- Job wanted - mysql,php,phpbb2 expert, payed wanted (Web Development Job Offers)
- How do I install Apache, MySQL, PHP on Linux? (PHP)
- [JOB] MySQL/PHP Engineer, Los Angeles, CA (Web Development Job Offers)
- Experience the FASTEST MySQL and PHP Hosting | Starting @ $2.50 per month (Web Hosting Deals)
- FASTEST MySQL and PHP Hosting, [Seeing is Believing] 75% OFF On Any Plan (Web Hosting Deals)
- Hardware Requirements for Fedora, Apache, MySQL and PHP on one machine (*nix Hardware Configuration)
- MySQL and PHP hosting (Linux Servers and Apache)
Other Threads in the MySQL Forum
- Previous Thread: mysql connection limit reached?
- Next Thread: mysql Installation Problem
| Thread Tools | Search this Thread |
Tag cloud for MySQL
"use" 1 agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright court crm data database design developer development distinct dui eliminate enter enterprise error eudora facebook form foss gartner gnu government gpl greenit groupware hiring hyperic images innerjoins insert ip joebrockmeier join keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron microsoft microsoftexchange mindtouch multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opengovernment opensource operand oracle penelope php priceupdating query referencedesign reorderingcolumns saas search select sharepoint simpledb spotify statement sugarcrm syntax techsupport thunderbird transparency update virtualization





