MySQL: How do you know if a command worked?

Im learning mySQL and everything is apparently working ok.The just problem now i’m having is that I need ideas of if some sort of query is successful or not necessarily.For example easily do a great “INSERT INTO” form query the place that the unique ID already exists inside database, mySQL does not complain and also anything, the idea just pretends them did it can be job.How do i know in the event the query failed

In addition, what personality encoding must i be using At this time I’m utilizing utf8_general_ci.Is that normal

Just increase ” or even die(“error around function xxx, sql:”.$sql.”
“.mysql_error() ); immediately after any query
ie
mysql_query($sql) and also die…
Write your current queries like a string:$sql = “insert into…”, to help you to display this query and also see where the fault is placed…

you cane easily see the final error generated with the function mysql_error()

therefore with PHP, after a person’s insert statement you might do like this:

if ($err = mysql_error())
replicate ‘INSERT BROKE ‘.$err;

In order to avoid the different id issue, let this database crash increment the primary key to suit your needs.In phpmyadmin, if you create a table, notice a domain called “extra” together with auto increment from the drop straight down, or the checkbox tagged A/I.Select this and modify ones insert statement to not assign every value for the primary important.The database will do it to suit your needs.

In MySQL, immediately after every wonder put a semicolon.Similar to this:

select * through table1;

U ll obtain the feedback you may need.

Have a shot at it.

Leave a Reply