Jump to content

Issue with PHP and SQL Drivers - undefined function mysql__construct


MikeAdkins

Recommended Posts

I have been chasing this issue now for a week.  I am new to PHP but have been programming in ASP.NET /VB for over 10 years.  I have taken the time to document my issue with PHP connecting to a Localhost database and will try to provide a brief explanation of where I am at. 

First some environment information.
OS - Windows 10 - 64bit.
DB - Both SQL Server Manager and MySQL Community.  Both running on my development machine.
PHP - Version 7.2.12 Development Server running Localhost.
From my PHP.INI file here are the extensions I am running.
extension=mysqli
extension=odbc
extension=pdo_mysql

 

  • Under the ;Paths and Directories  I made the following changes.
    • Uncommented include_path = ".;c:\php\includes"
    • Uncommented and edited extension_dir = "c:\PHP\EXT"

Note: I also had a number of PHP drivers for MSSQL but have abandoned that attempt and moved to MyPHP

//  MY TEST CODE \\

<?php

$link = mysql__construct("localhost", "mikea", "!QAZ2wsx");
mysql_select_db("database", $link);

$result = mysql__construct("SELECT * FROM actor", $link);
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

?>

// HERE IS THE ERROR \\

Note I got the same error when trying to use PHP and MSSQL.  And the same error with a number of different coding attempts.

Fatal error: Uncaught Error: Call to undefined function mysql__construct() in C:\PHP\www\site.php:3 Stack trace: #0 {main} thrown in C:\PHP\www\site.php on line 3

From the error syntax, it appears that the PHP is attempting to call a function out of the driver and it is not being found.  This could indicate that there is a compatibility issue the driver is not being called.  I have conducted a great deal of research and there is a lot about this problem but most are a few years old.  I have downloaded and installed the most current versions of PHP and the MySQL drivers.

I want to progress with PHP but need to be able to make connections to mySQL or MSSQL database.  I would prefer now to use MySQL as it is more popular on hosting sites.

 

Link to comment
Share on other sites

The old mysql extension was removed from PHP 7.  The best replacement is to use PDO with the appropriate driver.  You can also use mysqli, but most programmers prefer PDO.

You're also using 2 underscores instead of 1, but if you fixed that you would get the same error message because the mysql extension has been deprecated since 2004.  They finally removed it in PHP 7.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...