On Jul 13, 2009, at 10:03 AM, Govinda wrote:

I have this code:

      $db_billing=mysqli_connect(localhost,metheuser,mypass,billing);
if (mysqli_connect_error()) { die("Can't connect: " . mysqli_connect_error()); }

mysqli


      //$dbname = 'billing';
      $sql = "SHOW TABLES";

      $result = mysql_query($sql); // line 53

Now mysql, What are you doing?

Yes. 3 lashing. Thanks. I am not likely to neglect again remembering that mysql and mysqli are different and have different syntax.

unfortunately I am still in over my head enough to have to ask..

Here is what I have now:

$db_billing=mysql_connect(localhost,metheuser,mypass,billing);
if (!$db_billing) { die('Could not connect: ' . mysql_error()); }

        $sql = "SHOW TABLES";
        
        $result = mysql_query($sql);
        
        foreach(mysql_fetch_assoc($result) as $k => $v) { //line 62
        $ssql = "DESCRIBE ".mysql_real_escape_string($v);
        $rresult = mysql_query($ssql);
        echo "<b>".$k."</b>:<br />\n";
        echo "<pre>\n";
        print_r(mysql_fetch_assoc($rresult));
        echo "</pre>\n";
        echo "<br />\n";
        }

giving this error:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/meee/public_html/somedir/test.php on line 62

I read about:
-mysql_fetch_assoc
-mysql_query
-SHOW TABLES

but do not see why this should be failing. Why isn't $result a ' valid MySQL result resource'?

Better late then never! :)

I played around with your code tonight and got this working on a test server:


<?PHP

$db_billing = mysql_connect($DBHOST, $DBUSER, $DBPASS) or die("Could not connect: " .mysql_error());

$db_selected = mysql_select_db($DB, $db_billing);

        if(!$db_selected) {
                die("Can't use database: " . mysql_error());
        }


if (!$db_billing) { die('Could not connect: ' . mysql_error()); }

        $sql = "SHOW TABLES";

$result = mysql_query($sql) or die("query failed: " .mysql_error());
        $resulttest = mysql_fetch_assoc($result);


        foreach($resulttest as $k => $v) { //line 62
        $ssql = "DESCRIBE ".mysql_real_escape_string($v);
        $rresult = mysql_query($ssql);
        echo "<b>".$k."</b>:<br />\n";
        echo "<pre>\n";
        print_r(mysql_fetch_assoc($rresult));
        echo "</pre>\n";
        echo "<br />\n";
        }



?>

The only big difference from what you had is that I moved the mysql_fetch_assoc($result); into a separate line rather then running it from the foreach...

Let me know if that helps.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to