I have a project (exisiting) and I am ordered to continue it
but there's something strange
in my connection
<?php
include "adodb5/adodb.inc.php";
$config['mysqlhost'] = 'localhost';
$config['mysqluser'] = 'xxx';
$config['mysqlpass'] = 'yyy';
$config['mysqldb'] = 'zzz';
$DB = ADONewConnection('mysql');
$DB->Connect($config['mysqlhost'],$config['mysqluser'],$config['mysqlpass'],$config['mysqldb'],true);
?>
and if I try to call query (same queries as below) from this page, it works (and when I echo, it shows the value)
So I go to other page
<?
include ("inc/con.php");
?>
<?php
$sql = ("SELECT * FROM table");
$query = mysql_query($sql)or die($myQuery."<br/><br/>".mysql_error());
$result = mysql_fetch_array($query);
echo $result ['table id'];
?>
and the result is
Notice: Undefined variable: myQuery in C:\xampp\htdocs\d88\www\mypage.php on line 9
No database selected
is there anything wrong with it? since i try on con page, it works and when i include it to other page, it not working
You are not defining any $myQuery
either in inc/con.php
nor in the same file itself. Also you are not selecting any database with mysql_select_db
:
mysql_select_db($config['mysqldb']);
You are suggest, also, not to use mysql_*
functions as they are going to be deleted and are yet deprecated (and you can use PDO or mysqli).
Notice: I think $sql = ("SELECT * FROM table")
gets evaluated as $sql = true
.
You can not connect with ADODB connection and establish a query with mysql_query
. the syntax is something like this mysql_query ($query ,$con)
. $con
is optional but if you do not specify it, the last link opened by mysql_connect()
is assumed; but you have not any mysql_connect()
statement before
because of my version of php, i must use <?php ?>
instead of <? ?>
thanks for helping