PHP/mysql equivalent of PEAR"s tableInfo()??

PHP/mysql equivalent of PEAR"s tableInfo()??

am 12.07.2009 01:57:14 von Govinda

I have been using PEAR's tableInfo() to remind myself about the
columns in the table.. but now I want to see as much data as possible
about the table and its contents *without* using PEAR. (I.e. just
using built in stuff for mysqli.)

I have been looking through the manuals, even tried this:

$info = mysqli_query($db_billing,"SHOW FULL COLUMNS IN billing_clients
IN billing");
echo '

'. print_r($info) .'
';

which returns just:
mysqli_result Object
(
)
1


??

... and anyway SO much time gets wasted. I always aim to find things
myself.. but something so easy and quick.. it seems a shame to not
just ask.

Should I be asking this Q on another list? I see there are lists for
just "[mysql] General Discussion", and also for "MySQL and PHP" on
the http://lists.mysql.com/ site.. I don't need super deep stuff.
just the basics, all with respect to doing it from PHP.

What are you guys using to dump 'everything-you-always-wanted-to-know-
about-your-table'?

------------
Govinda
govinda.webdnatalk@gmail.com


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

Re: PHP/mysql equivalent of PEAR"s tableInfo()??

am 12.07.2009 02:15:32 von Daniel Brown

On Sat, Jul 11, 2009 at 19:57, Govinda wrote:
> I have been using PEAR's tableInfo() to remind myself about the columns i=
n
> the table.. =A0but now I want to see as much data as possible about the t=
able
> and its contents *without* using PEAR. =A0 (I.e. just using built in stuf=
f for
> mysqli.)

This is not mysqli_#() directly, but just mocked up here in this
email. Not guaranteed to work, but should give you the right idea at
least. ;-P

include('inc/config.php'); // Your configuration
include('inc/db.php'); // Your database connection info

$sql =3D "SHOW TABLES";

$result =3D mysql_query($sql);

foreach(mysql_fetch_assoc($result) as $k =3D> $v) {
$ssql =3D "DESCRIBE ".mysql_real_escape_string($v);
$rresult =3D mysql_query($ssql);
echo "".$k.":
\n";
echo "

\n";
print_r(mysql_fetch_assoc($rresult));
echo "
\n";
echo "
\n";
}
?>


--=20

daniel.brown@parasane.net || danbrown@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

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

Re: PHP/mysql equivalent of PEAR"s tableInfo()??

am 12.07.2009 23:49:42 von Govinda

> On Sat, Jul 11, 2009 at 19:57, Govinda
> wrote:
>> I have been using PEAR's tableInfo() to remind myself about the
>> columns in
>> the table.. but now I want to see as much data as possible about
>> the table
>> and its contents *without* using PEAR. (I.e. just using built in
>> stuff for
>> mysqli.)
>
> This is not mysqli_#() directly, but just mocked up here in this
> email. Not guaranteed to work, but should give you the right idea at
> least. ;-P
>
> > include('inc/config.php'); // Your configuration
> include('inc/db.php'); // Your database connection info
>
> $sql = "SHOW TABLES";
>
> $result = mysql_query($sql);
>
> foreach(mysql_fetch_assoc($result) as $k => $v) {
> $ssql = "DESCRIBE ".mysql_real_escape_string($v);
> $rresult = mysql_query($ssql);
> echo "".$k.":
\n";
> echo "

\n";
> print_r(mysql_fetch_assoc($rresult));
> echo "
\n";
> echo "
\n";
> }
> ?>


Dan I get roughly the idea, but alas I am stumped so easily in this
new ocean.. it frustrates me.

I have this code:

$db_billing=mysqli_connect(localhost,metheuser,mypass,billin g);
if (mysqli_connect_error()) { die("Can't connect: " .
mysqli_connect_error()); }
//$dbname = 'billing';
$sql = "SHOW TABLES";

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

foreach(mysql_fetch_assoc($result) as $k => $v) { // line 55
$ssql = "DESCRIBE ".mysql_real_escape_string($v);
$rresult = mysql_query($ssql);
echo "".$k.":
\n";
echo "
\n";
print_r(mysql_fetch_assoc($rresult));
echo "
\n";
echo "
\n";
}

Which is just giving these errors:

Warning: mysql_query() [function.mysql-query]: Access denied for user
'meee'@'localhost' (using password: NO) in /home/meee/public_html/
somedir/test.php on line 53

Warning: mysql_query() [function.mysql-query]: A link to the server
could not be established in /home/meee/public_html/somedir/test.php on
line 53

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

Warning: Invalid argument supplied for foreach() in /home/meee/
public_html/somedir/test.php on line 55

--
I am looking forward to when I have enough of my bearings that I can
just cruise around all the various docs and figure out my own
answers. Now there are just so many unknowns, I often can't tell
which way to even look to solve the issues.
-G


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

Re: PHP/mysql equivalent of PEAR"s tableInfo()??

am 13.07.2009 03:43:12 von Daniel Brown

Top-posting.

This would be an excellent question for Prune (CC'd) to field,
based on the error message.

Prune?


On Sun, Jul 12, 2009 at 17:49, Govinda wrote:
>> On Sat, Jul 11, 2009 at 19:57, Govinda
>> wrote:
>>>
>>> I have been using PEAR's tableInfo() to remind myself about the columns
>>> in
>>> the table.. =A0but now I want to see as much data as possible about the
>>> table
>>> and its contents *without* using PEAR. =A0 (I.e. just using built in st=
uff
>>> for
>>> mysqli.)
>>
>> =A0 This is not mysqli_#() directly, but just mocked up here in this
>> email. =A0Not guaranteed to work, but should give you the right idea at
>> least. =A0;-P
>>
>> >> include('inc/config.php'); // Your configuration
>> include('inc/db.php'); // Your database connection info
>>
>> $sql =3D "SHOW TABLES";
>>
>> $result =3D mysql_query($sql);
>>
>> foreach(mysql_fetch_assoc($result) as $k =3D> $v) {
>> =A0 =A0 =A0 $ssql =3D "DESCRIBE ".mysql_real_escape_string($v);
>> =A0 =A0 =A0 $rresult =3D mysql_query($ssql);
>> =A0 =A0 =A0 echo "".$k.":
\n";
>> =A0 =A0 =A0 echo "

\n";
>> =A0 =A0 =A0 print_r(mysql_fetch_assoc($rresult));
>> =A0 =A0 =A0 echo "
\n";
>> =A0 =A0 =A0 echo "
\n";
>> }
>> ?>
>
>
> Dan I get roughly the idea, but alas I am stumped so easily in this new
> ocean.. =A0it frustrates me.
>
> I have this code:
>
> =A0 =A0 =A0 =A0$db_billing=3Dmysqli_connect(localhost,metheuser,mypass,b i=
lling);
> =A0 =A0 =A0 =A0if (mysqli_connect_error()) { die("Can't connect: " .
> mysqli_connect_error()); }
> =A0 =A0 =A0 =A0//$dbname =3D 'billing';
> =A0 =A0 =A0 =A0$sql =3D "SHOW TABLES";
>
> =A0 =A0 =A0 =A0$result =3D mysql_query($sql); // line 53
>
> =A0 =A0 =A0 =A0foreach(mysql_fetch_assoc($result) as $k =3D> $v) { =A0// =
line 55
> =A0 =A0 =A0 =A0$ssql =3D "DESCRIBE ".mysql_real_escape_string($v);
> =A0 =A0 =A0 =A0$rresult =3D mysql_query($ssql);
> =A0 =A0 =A0 =A0echo "".$k.":
\n";
> =A0 =A0 =A0 =A0echo "
\n";
> =A0 =A0 =A0 =A0print_r(mysql_fetch_assoc($rresult));
> =A0 =A0 =A0 =A0echo "
\n";
> =A0 =A0 =A0 =A0echo "
\n";
> =A0 =A0 =A0 =A0}
>
> Which is just giving these errors:
>
> Warning: mysql_query() [function.mysql-query]: Access denied for user
> 'meee'@'localhost' (using password: NO) in
> /home/meee/public_html/somedir/test.php on line 53
>
> Warning: mysql_query() [function.mysql-query]: A link to the server could
> not be established in /home/meee/public_html/somedir/test.php on line 53
>
> Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL resu=
lt
> resource in /home/meee/public_html/somedir/test.php =A0on line 55
>
> Warning: Invalid argument supplied for foreach() in
> /home/meee/public_html/somedir/test.php =A0on line 55
>
> --
> I am looking forward to when I have enough of my bearings that I can just
> cruise around all the various docs and figure out my own answers. =A0 Now
> there are just so many unknowns, I often can't tell which way to even loo=
k
> to solve the issues.
> -G
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--=20

daniel.brown@parasane.net || danbrown@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

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

Re: PHP/mysql equivalent of PEAR"s tableInfo()??

am 13.07.2009 07:06:27 von zareef ahmed

--0015174c4616dff483046e8f4858
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

On Mon, Jul 13, 2009 at 3:19 AM, Govinda wrote:

> On Sat, Jul 11, 2009 at 19:57, Govinda
>> wrote:
>>
>>> I have been using PEAR's tableInfo() to remind myself about the columns
>>> in
>>> the table.. but now I want to see as much data as possible about the
>>> table
>>> and its contents *without* using PEAR. (I.e. just using built in stuff
>>> for
>>> mysqli.)
>>>
>>
>> This is not mysqli_#() directly, but just mocked up here in this
>> email. Not guaranteed to work, but should give you the right idea at
>> least. ;-P
>>
>> >> include('inc/config.php'); // Your configuration
>> include('inc/db.php'); // Your database connection info
>>
>> $sql = "SHOW TABLES";
>>
>> $result = mysql_query($sql);
>>
>> foreach(mysql_fetch_assoc($result) as $k => $v) {
>> $ssql = "DESCRIBE ".mysql_real_escape_string($v);
>> $rresult = mysql_query($ssql);
>> echo "".$k.":
\n";
>> echo "

\n";
>> print_r(mysql_fetch_assoc($rresult));
>> echo "
\n";
>> echo "
\n";
>> }
>> ?>
>>
>
>
> Dan I get roughly the idea, but alas I am stumped so easily in this new
> ocean.. it frustrates me.
>
> I have this code:
>
> $db_billing=mysqli_connect(localhost,metheuser,mypass,billin g);
> 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?


>
> foreach(mysql_fetch_assoc($result) as $k => $v) { // line 55
> $ssql = "DESCRIBE ".mysql_real_escape_string($v);
> $rresult = mysql_query($ssql);
> echo "".$k.":
\n";
> echo "
\n";
> print_r(mysql_fetch_assoc($rresult));
> echo "
\n";
> echo "
\n";
> }
>
> Which is just giving these errors:
>
> Warning: mysql_query() [function.mysql-query]: Access denied for user
> 'meee'@'localhost' (using password: NO) in
> /home/meee/public_html/somedir/test.php on line 53
>
> Warning: mysql_query() [function.mysql-query]: A link to the server could
> not be established in /home/meee/public_html/somedir/test.php on line 53
>
> Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result
> resource in /home/meee/public_html/somedir/test.php on line 55
>
> Warning: Invalid argument supplied for foreach() in
> /home/meee/public_html/somedir/test.php on line 55
>
> --
> I am looking forward to when I have enough of my bearings that I can just
> cruise around all the various docs and figure out my own answers. Now
> there are just so many unknowns, I often can't tell which way to even look
> to solve the issues.
> -G
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--
Zareef Ahmed :: A PHP Developer in India ( Delhi )
Homepage :: http://www.zareef.net

--0015174c4616dff483046e8f4858--

Re: PHP/mysql equivalent of PEAR"s tableInfo()??

am 13.07.2009 16:03:59 von Govinda

> I have this code:
>
> $db_billing=mysqli_connect(localhost,metheuser,mypass,billin g);
> 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 "".$k.":
\n";
echo "

\n";
print_r(mysql_fetch_assoc($rresult));
echo "
\n";
echo "
\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'?

-G

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

Re: PHP/mysql equivalent of PEAR"s tableInfo()??

am 16.07.2009 05:03:09 von Jason Pruim

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

>> I have this code:
>>
>> $db_billing=mysqli_connect(localhost,metheuser,mypass,billin g);
>> 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 "".$k.":
\n";
> echo "

\n";
> print_r(mysql_fetch_assoc($rresult));
> echo "
\n";
> echo "
\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:



$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 "".$k.":
\n";
echo "
\n";
print_r(mysql_fetch_assoc($rresult));
echo "
\n";
echo "
\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

Re: PHP/mysql equivalent of PEAR"s tableInfo()??

am 16.07.2009 05:31:27 von Govinda

--Apple-Mail-13-972431744
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit

>
> Better late then never! :)
>
> I played around with your code tonight and got this working on a
> test server:
>
>
> >
> $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 "".$k.":
\n";
> echo "

\n";
> print_r(mysql_fetch_assoc($rresult));
> echo "
\n";
> echo "
\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.

Thanks Jason :-)

What you just offered just shows info about only the first column in
the table.

I got this working to show info about all the columns in the table:

$ssql = "DESCRIBE billing_table";
$rresult = mysql_query($ssql);
echo "
\n";
while ($row = mysql_fetch_assoc($rresult)) {
print_r($row); //line 278
}
echo "
\n";
echo "
\n";

-G
--Apple-Mail-13-972431744--