Problem with mysql connections
4 posts
• Page 1 of 1
Problem with mysql connections
Today I`ve installed the php tools.
Simple php code worked fine. Then i want to try to retrieve some info from my db.
Then i`ve started my denwer tool pack, that manage apache.
So where is the problem?
Apache works fine, but every time i try to run this, i get next error
How could i fix this?
Simple php code worked fine. Then i want to try to retrieve some info from my db.
Then i`ve started my denwer tool pack, that manage apache.
So where is the problem?
- Code: Select all
<?php
mysql_connect("localhost","root","") or die("Could not connect: ".mysql_error());
mysql_select_db("mydb");
$sql="SELECT * FROM table1";
$reuslt=mysql_query($sql);
while($row=mysql_fetch_array($reuslt,MYSQL_ASSOC))
{
echo $row['id'].':'.$row['text']."<br/>";
}
?>
Apache works fine, but every time i try to run this, i get next error
Uncaught Error: Call to undefined function mysql_connect() in D:\GDrive\PHP Projects\PHPWebProject1\PHPWebProject1\index.php:2
Stack trace:
#0 {main}
thrown
How could i fix this?
- Jaood
- Posts: 2
- Joined: February 7th, 2017, 12:30 am
Re: Problem with mysql connections
Hello,
This means mysql extension is not installed in the php framework you are using.
Please check in the project properties, server tab what actual server is used. If you want to use apache you will need to set up Custom server here and fill in the virtual directory of your project. Then it should work fine, assuming mysql is installed in php on your apache.
Thanks!
This means mysql extension is not installed in the php framework you are using.
Please check in the project properties, server tab what actual server is used. If you want to use apache you will need to set up Custom server here and fill in the virtual directory of your project. Then it should work fine, assuming mysql is installed in php on your apache.
Thanks!
Miloslav Beno │ DEVSENSE s.r.o. │ @miloslavbeno │ miloslav@devsense.com
-
Miloslav Beno - Posts: 1252
- Joined: January 7th, 2012, 8:36 pm
Re: Problem with mysql connections
This isn't a PHP Tools issue, but I can help.
Firstly, mysql_connect is part of the php_mysql extension which was deprecated in PHP5.5. You will either need to use MySQLi, or PDO. I would suggest PDO.
I believe the MySQL PDO driver is enabled by default. To make sure or to add it, do this:
* Right click on your project name in the solution explorer.
* Click "properties"
* Click on the "server" tab on the left.
* Click the link labelled "Configuration file". You will probably need admin privileges to edit the php.ini file.
* Scroll all the way to the bottom where it says "[ExtensionList]"
* In that section add a line that says "extension=php_pdo_mysql.dll"
* Save the file, close notepad and restart your debug session in VS.
For how to use PDO, look at the PDO documentation on php.net: http://php.net/manual/en/book.pdo.php
Firstly, mysql_connect is part of the php_mysql extension which was deprecated in PHP5.5. You will either need to use MySQLi, or PDO. I would suggest PDO.
I believe the MySQL PDO driver is enabled by default. To make sure or to add it, do this:
* Right click on your project name in the solution explorer.
* Click "properties"
* Click on the "server" tab on the left.
* Click the link labelled "Configuration file". You will probably need admin privileges to edit the php.ini file.
* Scroll all the way to the bottom where it says "[ExtensionList]"
* In that section add a line that says "extension=php_pdo_mysql.dll"
* Save the file, close notepad and restart your debug session in VS.
For how to use PDO, look at the PDO documentation on php.net: http://php.net/manual/en/book.pdo.php
-
jazz - Posts: 41
- Joined: August 25th, 2016, 1:59 am
- Location: Canberra, Australia
Re: Problem with mysql connections
Thanks, your advice with mysqli works fine, so this topic can be closed.
- Jaood
- Posts: 2
- Joined: February 7th, 2017, 12:30 am
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 40 guests