SA-MP Forums Archive
mysql | always print 0... - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: mysql | always print 0... (/showthread.php?tid=269091)



mysql | always print 0... - EviLpRo - 14.07.2011

hello !

i do this:

pawn Код:
new Props;
mysql_query("SELECT * FROM `props`");
mysql_store_result();
Props = mysql_num_rows();
printf("MAX Props: %i",Props);
and this always print:

MAX Prosp: 0

this should be 4 not 0.

what's the problem here exactly?
thanks in advance helpers ...


Re: mysql | always print 0... - Scenario - 14.07.2011

You should try using this:

pawn Код:
mysql_affected_rows()



Re: mysql | always print 0... - Hornet600 - 14.07.2011

you better use sscanf to do it ... the way you doing it seems more like php and i never tested that way of script in pawn so can't help much..


Re: mysql | always print 0... - EviLpRo - 14.07.2011

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
You should try using this:

pawn Код:
mysql_affected_rows()
not working.


Re: mysql | always print 0... - whitedragon - 14.07.2011

Idiot quesion but have you insert any data?


Re: mysql | always print 0... - PrawkC - 14.07.2011

Try removing ` ` around props.


Re: mysql | always print 0... - [HiC]TheKiller - 14.07.2011

Turn on debugging at the top of your script
pawn Код:
mysql_debug(1);
Then check what the error is in the error log in the server directory.


Re: mysql | always print 0... - EviLpRo - 14.07.2011

here the debug text:

Код:
[02:34:44]  

[02:34:44] ---------------------------

[02:34:44] MySQL Debugging activated (07/15/11)

[02:34:44] ---------------------------

[02:34:44]  

[02:34:44] >> mysql_query( Connection handle: 1 )

[02:34:44] >> mysql_query() - Invalid connection handle. (You set: 1, Highest connection handle ID is 0).

[02:34:44] >> mysql_store_result( Connection handle: 1 )

[02:34:44] >> mysql_store_result() - Invalid connection handle. (You set: 1, Highest connection handle ID is 0).

[02:34:44] >> mysql_num_rows( Connection handle: 1 )

[02:34:44] >> mysql_num_rows() - Invalid connection handle. (You set: 1, Highest connection handle ID is 0).

[02:34:44] >> mysql_connect( )

[02:34:44] CMySQLHandler::CMySQLHandler() - constructor called.

[02:34:44] CMySQLHandler::CMySQLHandler() - Connecting to "localhost" | DB: "QDM" | Username: "root" ...

[02:34:44] CMySQLHandler::Connect() - Connection was successful.

[02:34:44] CMySQLHandler::Connect() - Auto-Reconnect has been enabled.



Re: mysql | always print 0... - dr.pepper - 14.07.2011

Which Plugin is this? G-StylezZz or StrickenKid's?


Quote:
Originally Posted by PrawkC
Посмотреть сообщение
Try removing ` ` around props.
This will make the query not function right ^.


Re: mysql | always print 0... - EviLpRo - 14.07.2011

Quote:
Originally Posted by dr.pepper
Посмотреть сообщение
Which Plugin is this? G-StylezZz or StrickenKid's?



This will make the query not function right ^.
edit:

G-sTyLeZzZ


Re: mysql | always print 0... - dr.pepper - 15.07.2011

pawn Код:
new Props, szQuery[128];
format(szQuery, sizeof(szQuery), "SELECT * FROM `Props`");
SendQuery(szQuery);
mysql_store_result();
Props = mysql_num_rows();
mysql_free_result();
printf("MAX Props: %d",Props);
Not sure if this would work ^


Re: mysql | always print 0... - EviLpRo - 15.07.2011

Quote:
Originally Posted by dr.pepper
Посмотреть сообщение
pawn Код:
new Props, szQuery[128];
format(szQuery, sizeof(szQuery), "SELECT * FROM `Props`");
SendQuery(szQuery);
mysql_store_result();
Props = mysql_num_rows();
mysql_free_result();
printf("MAX Props: %d",Props);
Not sure if this would work ^
again , not working


Re: mysql | always print 0... - dr.pepper - 15.07.2011

At the end of my code

pawn Код:
new Props, szQuery[128];
format(szQuery, sizeof(szQuery), "SELECT * FROM `Props`");
SendQuery(szQuery);
mysql_store_result();
Props = mysql_num_rows();
mysql_free_result();
printf("MAX Props: %d",Props);
Try adding this:
pawn Код:
return Props;
So it would look like this:
pawn Код:
new Props, szQuery[128];
format(szQuery, sizeof(szQuery), "SELECT * FROM `Props`");
SendQuery(szQuery);
mysql_store_result();
Props = mysql_num_rows();
mysql_free_result();
printf("MAX Props: %d",Props);
return Props;



Re: mysql | always print 0... - EviLpRo - 15.07.2011

not working ...
and from what the return ?


Re: mysql | always print 0... - dr.pepper - 15.07.2011

pawn Код:
new Props, szQuery[128], szString[128];
format(szQuery, sizeof(szQuery), "SELECT * FROM `Props`");
SendQuery(szQuery);
mysql_store_result();
Props = mysql_num_rows();
mysql_free_result();
format(szString, sizeof(szString), "Max Props= %d", props);
printf("MAX Props: %d",szString);
return Props;
idk lol, this should work ._.


Re: mysql | always print 0... - DRIFT_HUNTER - 15.07.2011

Check your connection (ping it) before and after


AW: Re: mysql | always print 0... - apfelhorst - 15.07.2011

Quote:
Originally Posted by EviLpRo
Посмотреть сообщение
here the debug text:

Код:
[02:34:44]  

[02:34:44] ---------------------------

[02:34:44] MySQL Debugging activated (07/15/11)

[02:34:44] ---------------------------

[02:34:44]  

[02:34:44] >> mysql_query( Connection handle: 1 )

[02:34:44] >> mysql_query() - Invalid connection handle. (You set: 1, Highest connection handle ID is 0).

[02:34:44] >> mysql_store_result( Connection handle: 1 )

[02:34:44] >> mysql_store_result() - Invalid connection handle. (You set: 1, Highest connection handle ID is 0).

[02:34:44] >> mysql_num_rows( Connection handle: 1 )

[02:34:44] >> mysql_num_rows() - Invalid connection handle. (You set: 1, Highest connection handle ID is 0).

[02:34:44] >> mysql_connect( )

[02:34:44] CMySQLHandler::CMySQLHandler() - constructor called.

[02:34:44] CMySQLHandler::CMySQLHandler() - Connecting to "localhost" | DB: "QDM" | Username: "root" ...

[02:34:44] CMySQLHandler::Connect() - Connection was successful.

[02:34:44] CMySQLHandler::Connect() - Auto-Reconnect has been enabled.
You are trying to use the query befor you are connected to any database. Try to Connect to MySQL before you use the query, not after^^


Re: mysql | always print 0... - EviLpRo - 15.07.2011

apfelhorst thank's you very much (:
this work