Re: [PHP] RE: non-auto increment question
Jerry Schwartz wrote: Being rather new to all this, I understood from the MySql manual that the auto_increment is to b e used immediately after an insertion not intermittently. My application is for administrators (the site owner designates) to update the database from and administration directory, accessed by user/password login... so there's really very little possibility of 2 people accessing at the same time. By using MAX + 1 I keep the id number in the $idIn and can reuse it in other INSERTS [JS] Are you looking for something like LAST_INSERT_ID()? If you INSERT a record that has an auto-increment field, you can retrieve the value that got inserted with SELECT LAST_INSERT_ID(). It is connection-specific, so you'll always have your own value. You can then save it to reuse, either as a session variable or (more easily) as a hidden field on your form. Thanks, Jerry, You hit the nail on the head.:) To refine my problem (and reduce my ignorance),here's what is happening on the form page: There is a series of INSERTs. The first inserts all the columns of book table except for the id, which I do not specify as it if auto-insert. In subsequent tables I have to reference the book.id (for transitional tables like book_author(refers authors to book) etc. If I understand it correctly, I must retrieve (SELECT LAST_INSERT_ID()) after the first INSERT and before the following insert; and save the id as a string ($id)...e.g. $sql = SELECT LAST_INSERT_ID() AS $id I need clarification on the AS $id - should this be simply id(does this have to be turned into a value into $id or does $id contain the value? And how do I retrieve it to use the returned value for the next $sql = INSERT ... - in other words, is the id or $id available for the next directive or do I have to do something like $id = id? I'm trying to figure this out with some trials but my insert does not work from a php file - but it works from command-line... that's another post. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
catch the error
What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: catch the error
Hi PJ, Could it be that you have //include (lib/db1.php); commented out? Try uncommenting that line and see what happens. The error message will always print because the query is never executing properly if you have the db connections file commented out. On Thu, Feb 26, 2009 at 12:28 PM, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php); // Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: catch the error
It is commented out because I am using mysql_connect I don't think it would be good to use both, since the db1 references another db. But even when I use the db1.php and change the database and table, I get the same error message. But what I did miss is my typo in What is wrond with this file? :-) Hi PJ, Could it be that you have //include (lib/db1.php); commented out? Try uncommenting that line and see what happens. The error message will always print because the query is never executing properly if you have the db connections file commented out. On Thu, Feb 26, 2009 at 12:28 PM, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: catch the error
what's the error message? On Thu, Feb 26, 2009 at 11:46 AM, PJ af.gour...@videotron.ca wrote: It is commented out because I am using mysql_connect I don't think it would be good to use both, since the db1 references another db. But even when I use the db1.php and change the database and table, I get the same error message. -- Jim Lyons Web developer / Database administrator http://www.weblyons.com
RE: Upgrade story / request for insight
-Original Message- From: walterh...@gmail.com [mailto:walterh...@gmail.com] On Behalf Of Walter Heck Sent: Wednesday, February 25, 2009 11:43 PM To: Jerry Schwartz Cc: Gary W. Smith; Claudio Nanni; MySql Subject: Re: Upgrade story / request for insight Maybe this could help you: http://blog.olindata.com/2008/11/testing-environment-setting-up- virtualbox-for-easy-vm/ http://blog.olindata.com/2009/02/testing-environment-installing-centos- 52-on-virtualbox/ No need for a separate machine :) [JS] Aha! Thanks for the suggestion. I had thought about trying to set up a virtual machine on our production system, but it never occurred to me to do it the other way around. I'll have to look into it, but I'm pretty sure that CentOS is pay-to-play. Right now things are tough all over, so I don't think I could get the money for it unless it is very cheap. Since the goal is to replicate our production environment, something like Ubuntu wouldn't cut it. It might be fun for dinking around; I just installed it while typing this email. Slick. regards, Walter OlinData: Professional services for MySQL Support * Consulting * Administration http://www.olindata.com On Wed, Feb 25, 2009 at 11:00 PM, Jerry Schwartz jschwa...@the-infoshop.com wrote: From: Gary W. Smith [mailto:g...@primeexalia.com] Sent: Wednesday, February 25, 2009 4:36 PM To: Claudio Nanni; Jerry Schwartz Cc: MySql Subject: RE: Upgrade story / request for insight Jerry, To touch a little more on Claudio's statement, you are trying to compare monkey's and trucks when you talk about mysql on these two different OS's. Microsoft is a different best when it comes to the install. [JS] That part I understand. I was more concerned with checking my production code to make sure nothing broke. I was astonished that the Windows upgrade didn't go through smoothly, and that's what led to my original post. What caught my attention though is you are running mysql 4.0 on CentOS. This means that you are probably running an older version of CentOS as 5.x comes with mysql 5.0 (I believe). You might want to setup a similar environment with the same OS and do a db upgrade on that (without your actual data) and see if everything works first. You might find some lib issues with the older CentOS. [JS] Thanks for the warning. I'm on CentOS 4.7, and I wouldn't have thought about the library issues. Unfortunately, I don't have another Linux machine to play with. Gary _ From: Claudio Nanni [mailto:claudio.na...@gmail.com] Sent: Wed 2/25/2009 12:50 PM To: Jerry Schwartz Cc: MySql Subject: Re: Upgrade story / request for insight Hi Jerry, probably does not help you very much and excuse me in advance for this, but there is little use in having a development/preproduction system on different architecture, none of the issues you faced with windows (services installation probably) will show up on a CentOS box. In particular an upgrade which involves filesystem and services installation is quite different between Win and Linux. From a 'service' point of view (MySQL server) there will be no difference for any client in accessing a Win or a Linux box, but from a maintenance point of view you are facing problems that are peculiar of the platform, in windows in fact mysql is installed as a service so you should check windows services as well. In any case I strategy I always used for migration is to install the new version and export / import data, this is good because you have two parallel servers up and you can compare and test both of them, provided you are using different 'sockets', that is different PORT if just using TCP/IP connection method. Cheers Claudio Nanni 2009/2/25 Jerry Schwartz jschwa...@the-infoshop.com My ultimate goal is to upgrade a production server (MySQL 4.1.22 on CentOS) to a modern 5.1 release. My development system is a Windows Vista x86 machine, and although the process is not that similar I decided to try an upgrade there. (I've never done one.) I figured this would give me some insight as to whether or not our code would break. The upgrade from 5.0.45 to 5.1.31 was a horror show! I downloaded the 5.1.31 msi package, and ran the wizard. The Windows notes seemed to say that for this upgrade I didn't need to uninstall the old one, and that might have been a mistake. In any case, the wizard attempted to install 5.1.31, but after it asked me if I wanted to configure an instance it just disappeared. I ran the instance configuration wizard by hand, and it showed two different server versions. The older one was apparently still running. I tried shutting it down; I tried deleting it with the sc command, which (after a reboot) did make it go away; but the instance configuration wizard still listed it. In fact, it still listed it after I renamed the MySQL 5.0 directory. The 5.1 server would attempt to start, but would fall over dead
Re: catch the error
Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php); // Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Cheers, Ricardo Dias Marques lists AT ricmarques DOT net -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: catch the error
ok, well if that's the case then do this $db = mysql_connect('biggie', 'user', 'password', 'test'); That should fix the problem. On Thu, Feb 26, 2009 at 12:46 PM, PJ af.gour...@videotron.ca wrote: It is commented out because I am using mysql_connect I don't think it would be good to use both, since the db1 references another db. But even when I use the db1.php and change the database and table, I get the same error message. But what I did miss is my typo in What is wrond with this file? :-) Hi PJ, Could it be that you have //include (lib/db1.php); commented out? Try uncommenting that line and see what happens. The error message will always print because the query is never executing properly if you have the db connections file commented out. On Thu, Feb 26, 2009 at 12:28 PM, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php); // Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: [PHP] catch the error
Ashley Sheridan wrote: On Thu, 2009-02-26 at 12:28 -0500, PJ wrote: What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php); // Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com I'd say it was the way you are trying to connect to your database. This is how it's done: $db_host = 'localhost'; $db_user = 'root'; $db_password = ''; $db_name = 'database_name'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); You see, first you have to cerate a connection to the database server, then you have to select your database on that connection. In your example, 'biggie' is the name of a server where your database resides, and 'test', well, what can I say? This 4th parameter should be a boolean indicating whether or not a new connection should be made upon successive calls to mysql_connect. Ash www.ashleysheridan.co.uk OK, I see my error...understood and fixed... but it still does not work. But I did have an error - the include was wrong - missing ../ Something is till amiss... the include configuration works, this does not? Why? ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'myuser'; $db_pass = 'my_pwd'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: catch the error
Jim Lyons wrote: what's the error message? it's in the script/// Error performing query: of Error performing 1st query: - whatever I input. But I had an error in the include location... that's fixed and it works, but not the rest as corrected: ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? On Thu, Feb 26, 2009 at 11:46 AM, PJ af.gour...@videotron.ca mailto:af.gour...@videotron.ca wrote: It is commented out because I am using mysql_connect I don't think it would be good to use both, since the db1 references another db. But even when I use the db1.php and change the database and table, I get the same error message. -- Jim Lyons Web developer / Database administrator http://www.weblyons.com -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: catch the error
Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: catch the error
Darryle Steplight wrote: ok, well if that's the case then do this $db = mysql_connect('biggie', 'user', 'password', 'test'); Ashley pointed out that the 4th parameter is not right - belongs in mysql_select_db. Here it is corrected: (but it still does not work) ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'my_user'; $db_pass = 'my_pass'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? That should fix the problem. On Thu, Feb 26, 2009 at 12:46 PM, PJ af.gour...@videotron.ca wrote: It is commented out because I am using mysql_connect I don't think it would be good to use both, since the db1 references another db. But even when I use the db1.php and change the database and table, I get the same error message. But what I did miss is my typo in What is wrond with this file? :-) Hi PJ, Could it be that you have //include (lib/db1.php); commented out? Try uncommenting that line and see what happens. The error message will always print because the query is never executing properly if you have the db connections file commented out. On Thu, Feb 26, 2009 at 12:28 PM, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: catch the error
Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php); // Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php); // Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
RE: [PHP] RE: non-auto increment question
-Original Message- From: PJ [mailto:af.gour...@videotron.ca] Sent: Thursday, February 26, 2009 11:27 AM To: Jerry Schwartz Cc: a...@ashleysheridan.co.uk; 'Gary W. Smith'; 'MySql'; php- gene...@lists.php.net Subject: Re: [PHP] RE: non-auto increment question Jerry Schwartz wrote: Being rather new to all this, I understood from the MySql manual that the auto_increment is to b e used immediately after an insertion not intermittently. My application is for administrators (the site owner designates) to update the database from and administration directory, accessed by user/password login... so there's really very little possibility of 2 people accessing at the same time. By using MAX + 1 I keep the id number in the $idIn and can reuse it in other INSERTS [JS] Are you looking for something like LAST_INSERT_ID()? If you INSERT a record that has an auto-increment field, you can retrieve the value that got inserted with SELECT LAST_INSERT_ID(). It is connection-specific, so you'll always have your own value. You can then save it to reuse, either as a session variable or (more easily) as a hidden field on your form. Thanks, Jerry, You hit the nail on the head.:) [JS] I'm glad to hear it. To refine my problem (and reduce my ignorance),here's what is happening on the form page: There is a series of INSERTs. The first inserts all the columns of book table except for the id, which I do not specify as it if auto- insert. In subsequent tables I have to reference the book.id (for transitional tables like book_author(refers authors to book) etc. [JS] Okay. If I understand it correctly, I must retrieve (SELECT LAST_INSERT_ID()) after the first INSERT and before the following insert; and save the id as a string ($id)...e.g. $sql = SELECT LAST_INSERT_ID() AS $id [JS] You are confusing database column names with PHP variable names. You don't need an alias at all, unless you feel like it for reasons of convenience or style. Assume that $title is your book title, and that the first column is an auto-increment field. The first two queries should look like $query_insert = INSERT INTO book VALUES (NULL, '$title', ...); and $query_select_id = SELECT LAST_INSERT_ID(); Of course, you need to actually execute the two queries. The first one doesn't return anything (check for errors, of course). The second one retrieves the ID of the record you just inserted. Now retrieve the value returned by the SELECT statement and put it into a variable. You'll use something like $row_selected = mysql_query($query_select_id) or die($query_select_id failed); $last_id = mysql_fetch_array($row_selected) or die(Unable to fetch last inserted ID); and you have what you want. You can now use $last_id anywhere you want, until your script ends. This is all very simplified, but I think you can get my drift. Regards, Jerry Schwartz The Infoshop by Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 www.the-infoshop.com www.giiexpress.com www.etudes-marche.com I need clarification on the AS $id - should this be simply id(does this have to be turned into a value into $id or does $id contain the value? And how do I retrieve it to use the returned value for the next $sql = INSERT ... - in other words, is the id or $id available for the next directive or do I have to do something like $id = id? I'm trying to figure this out with some trials but my insert does not work from a php file - but it works from command-line... that's another post. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
RE: catch the error
-Original Message- From: PJ [mailto:af.gour...@videotron.ca] Sent: Thursday, February 26, 2009 12:28 PM To: php-gene...@lists.php.net; MySql Subject: catch the error What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. [JS] You need $db = mysql_connect('biggie', 'user', 'password', 'test'); -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=jschwa...@the- infoshop.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
RE: [PHP] RE: non-auto increment question
Here's how I mostly do it (albeit simplified): $query = INSERT INTO `sometable`(`title`,`content`) VALUES('$title','$content'); $result = mysql_query($query); $autoId = mysql_insert_id($result); $query = INSERT INTO `another_table`(`link_id`,`value`) VALUES($autoId,'$value'); $result = mysql_query($query); No need to call another query to retrieve the last inserted id, as it is tied to the last query executed within this session. Ash www.ashleysheridan.co.uk [JS] Ashley is absolutely right, I'd forgotten about the mysql_insert_id shorthand. (I'm a one-man band, and for the last week or two I've been immersed in VB for Access forms.) Not only is she right, but her way is better. Presumably a language's internal code is maintained as the specific database changes. You can make yourself more independent of the specific database by using the PDO abstraction, although I would save that for a rainy weekend. Regards, Jerry Schwartz The Infoshop by Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 www.the-infoshop.com www.giiexpress.com www.etudes-marche.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: [PHP] Re: catch the error
Additionally regarding the error handling , add this to the op of your script. ini_set(display_errors,true); error_reporting(E_STRICT|E_ALL); and post the output of your error message. On Thu, Feb 26, 2009 at 1:40 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote: Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php); // Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php); // Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com I agree. I wouldn't trust me at all! ;) Ash www.ashleysheridan.co.uk -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: catch the error
Jerry Schwartz wrote: -Original Message- From: PJ [mailto:af.gour...@videotron.ca] Sent: Thursday, February 26, 2009 12:28 PM To: php-gene...@lists.php.net; MySql Subject: catch the error What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. [JS] You need $db = mysql_connect('biggie', 'user', 'password', 'test'); -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=jschwa...@the- infoshop.com I think the problem here has been that this is such a basic operation and most of us just are too busy with more complicated stuff...that we didn't catch it... ? //include (../lib/db1.php);// Connect to database $db_host = ''; $db_user = ''; $db_pass = ''; $db_name = ''; $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 3st query: . mysql_error() . /P); } echo $sql1; echo br /; echo $db_select; exit(); ? anyway, I am learning a lot... thanks, guys... you're all great... I have lots more coming... :-D -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: [PHP] Re: catch the error
Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote: Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com I agree. I wouldn't trust me at all! ;) Ash www.ashleysheridan.co.uk Yeah very stupid of me...but I found the error: see if you can catch it: ? //include (../lib/db1.php);// Connect to database $db_host = 'xxx'; $db_user = 'xxx; $db_pass = 'xxx'; $db_name = 'xxx'; $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 3st query: . mysql_error() . /P); } echo $sql1; echo br /; echo $db_select; exit(); ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: [PHP] Re: catch the error
Here's the working code... ? //include (../lib/db1.php);// Connect to database $db_host = ''; $db_user = ''; $db_pass = ''; $db_name = ''; $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 3st query: . mysql_error() . /P); } echo $sql1; echo br /; echo $db_select; exit(); ? This works fine either as is or using the include... :-) 9el wrote: But the question is PJ, have you got it out of errors yet? :) www.twitter.com/nine_L http://www.twitter.com/nine_L www.lenin9l.wordpress.com http://www.lenin9l.wordpress.com --- Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get a Free CD of Ubuntu mailed to your door without any cost. Visit : www.ubuntu.com http://www.ubuntu.com -- 2009/2/27 Ashley Sheridan a...@ashleysheridan.co.uk mailto:a...@ashleysheridan.co.uk On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote: Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca mailto:af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca mailto:af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test') or die(Error connecting DB.mysql_error()); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db) or die(PError performing 1st query: .mysql_error() . /P); ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com mailto:p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com I agree. I wouldn't trust me at all! ;) Ash www.ashleysheridan.co.uk http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: [PHP] RE: non-auto increment question
Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:44 -0500, Jerry Schwartz wrote: Here's how I mostly do it (albeit simplified): $query = INSERT INTO `sometable`(`title`,`content`) VALUES('$title','$content'); $result = mysql_query($query); $autoId = mysql_insert_id($result); $query = INSERT INTO `another_table`(`link_id`,`value`) VALUES($autoId,'$value'); $result = mysql_query($query); No need to call another query to retrieve the last inserted id, as it is tied to the last query executed within this session. Ash www.ashleysheridan.co.uk [JS] Ashley is absolutely right, I'd forgotten about the mysql_insert_id shorthand. (I'm a one-man band, and for the last week or two I've been immersed in VB for Access forms.) Not only is she right, but her way is better. Presumably a language's internal code is maintained as the specific database changes. You can make yourself more independent of the specific database by using the PDO abstraction, although I would save that for a rainy weekend. Regards, Jerry Schwartz The Infoshop by Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 www.the-infoshop.com www.giiexpress.com www.etudes-marche.com I just checked, and yep, I'm definitely still a he ;) I never thought otherwise... but then I was wondering... there are too many actresses with the same name... ;-) -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: catch the error [OFF TOPIC]
Gentlemen, my opinion is that this post is OFF TOPIC, let's don't wade into the PHP world here, let's keep this list clean and focused on MySQL. If the insert works from console and not from PHP probably is PHP related problem and there are thousands of lists on PHP. This is the most professional list on MySQL, let's keep it on MySQL. Phil, this is my humble opinion. Regards, Claudio Nanni PJ wrote: What is wrond with this file? same identical insert works from console but not from this file :-( html head titleUntitled/title /head body ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? /body /html Seems to be good to print out the error message, but that's all. db not written. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: [PHP] Re: catch the error
Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:56 -0500, PJ wrote: Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote: Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com I agree. I wouldn't trust me at all! ;) Ash www.ashleysheridan.co.uk Yeah very stupid of me...but I found the error: see if you can catch it: ? //include (../lib/db1.php);// Connect to database $db_host = 'xxx'; $db_user = 'xxx; $db_pass = 'xxx'; $db_name = 'xxx'; $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 3st query: . mysql_error() . /P); } echo $sql1; echo br /; echo $db_select; exit(); ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com $db_user has not had the string terminated. pray tell was that the answer you were looking for?! Ash www.ashleysheridan.co.uk No. Damn those typos! What seems to have made it work is just $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); not using mysql_select in a string but would you use it in a string? how why? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
RE: [PHP] RE: non-auto increment question
Sorry, I should know better. -Original Message- From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: Thursday, February 26, 2009 1:51 PM To: Jerry Schwartz Cc: 'PJ'; 'Gary W. Smith'; 'MySql'; php-gene...@lists.php.net Subject: RE: [PHP] RE: non-auto increment question On Thu, 2009-02-26 at 13:44 -0500, Jerry Schwartz wrote: Here's how I mostly do it (albeit simplified): $query = INSERT INTO `sometable`(`title`,`content`) VALUES('$title','$content'); $result = mysql_query($query); $autoId = mysql_insert_id($result); $query = INSERT INTO `another_table`(`link_id`,`value`) VALUES($autoId,'$value'); $result = mysql_query($query); No need to call another query to retrieve the last inserted id, as it is tied to the last query executed within this session. Ash www.ashleysheridan.co.uk [JS] Ashley is absolutely right, I'd forgotten about the mysql_insert_id shorthand. (I'm a one-man band, and for the last week or two I've been immersed in VB for Access forms.) Not only is she right, but her way is better. Presumably a language's internal code is maintained as the specific database changes. You can make yourself more independent of the specific database by using the PDO abstraction, although I would save that for a rainy weekend. Regards, Jerry Schwartz The Infoshop by Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 www.the-infoshop.com www.giiexpress.com www.etudes-marche.com I just checked, and yep, I'm definitely still a he ;) Ash www.ashleysheridan.co.uk -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: [PHP] Re: catch the error
Ashley Sheridan wrote: On Thu, 2009-02-26 at 14:15 -0500, PJ wrote: Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:56 -0500, PJ wrote: Ashley Sheridan wrote: On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote: Hi PJ, $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; Everyone here is trying to help you and that's cool, but EVERYONE on this list may not be so nice. The above credentials is definitely the type of information you want to keep private, unless you don't mind people potentially accessing your database tables and doing whatever they like with them. I suggest doing something like $db_host = 'localhost; $db_user = 'foo'; $db_pass= ''bar; $db_name =''xx; if you are going to post it on the list. On Thu, Feb 26, 2009 at 1:22 PM, PJ af.gour...@videotron.ca wrote: Ricardo Dias Marques wrote: Hi PJ, On Thu, Feb 26, 2009 at 17:28, PJ af.gour...@videotron.ca wrote: What is wrond with this file? same identical insert works from console but not from this file :-( [snip] ? //include (lib/db1.php);// Connect to database mysql_connect('biggie', 'user', 'password', 'test'); $sql1 = INSERT INTO example (name, age) VALUES ('Joe Blow', '69'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? I haven't coded in PHP for a long time, but I think that your problem is in this line: $result1 = mysql_query($sql1,$db); Up to that point, $db (that should point to a database link identifier) is not defined. You probably want to assign the mysql_connect result to that $db variable. So, I think that you will solve your problem by changing your mysql_connect line FROM the current form: mysql_connect('biggie', 'user', 'password', 'test'); .. TO this one: $db = mysql_connect('biggie', 'user', 'password', 'test'); Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below ? //include (../lib/db1.php);// Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gu...@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 1st query: . mysql_error() . /P); exit(); } ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=dstepli...@gmail.com I agree. I wouldn't trust me at all! ;) Ash www.ashleysheridan.co.uk Yeah very stupid of me...but I found the error: see if you can catch it: ? //include (../lib/db1.php);// Connect to database $db_host = 'xxx'; $db_user = 'xxx; $db_pass = 'xxx'; $db_name = 'xxx'; $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); $sql1 = INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75'); $result1 = mysql_query($sql1,$db); if (!$result1) { echo(PError performing 3st query: . mysql_error() . /P); } echo $sql1; echo br /; echo $db_select; exit(); ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com $db_user has not had the string terminated. pray tell was that the answer you were looking for?! Ash www.ashleysheridan.co.uk No. Damn those typos! What seems to have made it work is just $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db); not using mysql_select in a string but would you use it in a string? how why? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com Yeah, you'd typo'd on the variable name. Also, the $ sign doesn't actually denote a string, but a scaler variable, which can be any type, complex or simple. I type too fast and am too speedy... :-) I'll have to look up about the variables. Thanks good night. 'Til the morrow. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
RE: [PHP] RE: non-auto increment question
Being rather new to all this, I understood from the MySql manual that the auto_increment is to b e used immediately after an insertion not intermittently. My application is for administrators (the site owner designates) to update the database from and administration directory, accessed by user/password login... so there's really very little possibility of 2 people accessing at the same time. By using MAX + 1 I keep the id number in the $idIn and can reuse it in other INSERTS -- The statement is confusing at best. For the casual user auto_increment is the way to do. I say for the casual user. That is typical me and you. Basically if you do an insert a unique value is inserted at the time of the insert. As mentioned, there are ways to get this value back in the return. Now why I say it's for the casual user is because if you are using triggers then you can do things prior to this value being used and then the statement above is correct. But you are not going to be using triggers... So, put an auto_increment on the key field and find one of the 2^16 samples of how this works with PHP. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
batch insert
In C API, I want to insert 1 sql. I must have one strSql= insert into tables hello id ,blob values(?,?),(?,?),(?,?)..。 then bind every pos with mysql_stmt_bind_param(). then to exec. In C API don't have batchexec。 if I can have strSQL = inset into tables hello id,blob values1((?),(?)). like this strSQL thank you ereryone. _ Drag n’ drop—Get easy photo sharing with Windows Live™ Photos. http://www.microsoft.com/windows/windowslive/products/photos.aspx