Problem with mysql connections

PHP Tools [?] extends Visual Studio with set of advanced features to work more efficiently with PHP code.

Problem with mysql connections

Postby Jaood » February 7th, 2017, 12:36 am

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?
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

Postby Miloslav Beno » February 7th, 2017, 9:07 am

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!
Miloslav Beno │ DEVSENSE s.r.o. │ @miloslavbenomiloslav@devsense.com
User avatar
Miloslav Beno
 
Posts: 1252
Joined: January 7th, 2012, 8:36 pm

Re: Problem with mysql connections

Postby jazz » February 7th, 2017, 9:56 pm

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
Try Hazaar MVC - http://www.hazaarmvc.com
The MVC Framework that makes PHP not suck!

Image
User avatar
jazz
 
Posts: 41
Joined: August 25th, 2016, 1:59 am
Location: Canberra, Australia

Re: Problem with mysql connections

Postby Jaood » February 13th, 2017, 8:06 pm

Thanks, your advice with mysqli works fine, so this topic can be closed.
Jaood
 
Posts: 2
Joined: February 7th, 2017, 12:30 am


Return to PHP Tools

Who is online

Users browsing this forum: No registered users and 79 guests

User Control Panel

Login

Who is online

In total there are 79 users online :: 0 registered, 0 hidden and 79 guests (based on users active over the past 5 minutes)
Most users ever online was 398 on April 19th, 2024, 9:04 pm

Users browsing this forum: No registered users and 79 guests