aha rin aha rin - 5 months ago 20
PHP Question

php - can't connect to mysql using different method

host = ***.**.**.**
username = ****
password = ****
db name = test1
port = 3307


I can connect to my MySQL database using this php

<?php
$servername = "***.**.*.**";
$username = "***";
$password = "***";
$dbname = "test1";
$dbport = "3307";

$conn = new mysqli($servername, $username, $password, $dbname, $dbport);
?>


but I can't connect using this

<?php
define ("DB_ACCESS", "mysqli");
define ("DB_HOST", "***.**.*.**");
define ("DB_NAME", "test1");
define ("DB_USER", "****");
define ("DB_PASSWORD", "****");
define ("DB_PORT", "3307");

global $dbdtk_dbaccess, $dbdtk_dbhost, $dbdtk_dbuser, $dbdtk_dbpasswd,
$dbdtk_dbname, $dbdtk_dbport;

$dbdtk_dbaccess = DB_ACCESS;
$dbdtk_dbhost = DB_HOST;
$dbdtk_dbuser = DB_USER;
$dbdtk_dbpasswd = DB_PASSWORD;
$dbdtk_dbname = DB_NAME;
$dbdtk_dbport = DB_PORT;

$db = &ADONewConnection($dbdtk_dbaccess);
$db->debug = 0;
$db->Connect($dbdtk_dbhost, $dbdtk_dbuser, $dbdtk_dbpasswd,
$dbdtk_dbname, dbdtk_dbport);
$ADODB_FETCH_MODE = ADODB_FETCH_BOTH;
?>


what's wrong with my code? I have to use both for my app. Thanks for everyone's help.

Answer

I've figured it out by adding

$db->port = 3307;

so it become

<?php
define ("DB_ACCESS", "mysqli");
define ("DB_HOST", "***.**.*.**");
define ("DB_NAME", "test1");
define ("DB_USER", "****");
define ("DB_PASSWORD", "****");

global $dbdtk_dbaccess, $dbdtk_dbhost, $dbdtk_dbuser, $dbdtk_dbpasswd,
$dbdtk_dbname;

$dbdtk_dbaccess = DB_ACCESS;
$dbdtk_dbhost   = DB_HOST;
$dbdtk_dbuser   = DB_USER;
$dbdtk_dbpasswd = DB_PASSWORD;
$dbdtk_dbname   = DB_NAME;

$db = &ADONewConnection($dbdtk_dbaccess);
$db->port = 3307;
$db->debug = 0;
$db->Connect($dbdtk_dbhost, $dbdtk_dbuser, $dbdtk_dbpasswd,
$dbdtk_dbname);
$ADODB_FETCH_MODE = ADODB_FETCH_BOTH;
?>
Comments