Jump to content

Migrated working app to locally hosted and have mysql_connect errors


Recommended Posts

I have a site that is working on a hosted server. I setup PHP, MYSQL, and IIS on my local server. PHPMYADMIN works so I know that php is working. Im not that great at coding, and I keep getting errors at every turn. The hosted version of PHP that works is 5.6.-29, and the only version I could obtain was 5.6.30. 

 

 

 

{"errorMsg":"ErrNo: 8192, 
\r\n ErrStr: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead, 
\r\n ErrFile: C:\\inetpub\\wwwroot\\system\\core\\SpcDb.php, 
\r\n ErrLine: 108 (Cannot open file errors.log)","success":false}

 

So I changed it to mysqli, then I got an error about mysql_select, so I changed it to mysqli_select and now im getting 

 

 

{"errorMsg":"ErrNo: 2, 
\r\n ErrStr: mysqli_select_db() expects exactly 2 parameters, 1 given, 
\r\n ErrFile: C:\\inetpub\\wwwroot\\system\\core\\SpcDb.php, 
\r\n ErrLine: 109 (Cannot open file errors.log)","success":false}

 

What is confusing is that this test DB script works with mysql_connect just fine.

 

Here is my original connection code...

      * Gets default mysql connection
     *
     * @param void
     *
     * @return resource
     */
    public static function getDbConn($dbParams = null) {
        if ($dbParams !== null) {
            $host = $cfg['host'];
            $username = $cfg['username'];
            $password = $cfg['password'];
            $dbName = $cfg['dbName'];
        } else {
            if (self::$_conn) {
                return self::$_conn;
            }

            $host = SPC_DB_HOST;
            $username = SPC_DB_USERNAME;
            $password = SPC_DB_PASSWORD;
            $dbName = SPC_DB_DBNAME;
        }

        self::$_conn = mysqli_connect($host, $username, $password);
        mysqli_select_db($dbName);

        return self::$_conn;
    }

You cannot just through an i on the end of the deprecated functions. Take some time and read the manual. You should be using PDO anyways. https://phpdelusions.net/pdo

Edited by benanamen

You cannot just through an i on the end of the deprecated functions. Take some time and read the manual. You should be using PDO anyways. https://phpdelusions.net/pdo

Im not that good at coding. Im I.T. and was hoping someone can help me resolve this. Why is it that mysql_connect works on my test script but not this original script?

Edited by allinarush

 

\r\n ErrStr: mysqli_select_db() expects exactly 2 parameters, 1 given,

There is a clue in that error message - wrong parameters. So look up the function mysqli_select_db in the PHP manual and see what the parameters should be

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.