RE: [PHP-DB] Retrieving Image Location in MySQL
Matya, Ha, ha, ha! Thank you good friend. I did say I didn't try the code :-) AF> Please note, I haven't tried this. It just seems plausible. I apologize if I confused anyone. I just meant to show how the parameter could help retrieve a picture. I wasn't too concerned with the particulars. Hopefully the concept is sound. If not, please do flame my note so no one attempts it. Be Well, A- -Original Message- From: Mattyasovszky Janos [mailto:m...@matya.hu] Sent: Monday, March 02, 2009 9:29 AM To: php-db@lists.php.net Subject: Re: [PHP-DB] Retrieving Image Location in MySQL Fortuno, Adam írta: > //Write a query to pull out the picture's path > $sql = "SELECT path FROM Image WHERE ID = %s"; > mysql_real_escape_string($value); Sorry, but this won't work, since you don't map the value of the escaped $value to the %s, lets say with sprintf()... Regards, Matya -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Retrieving Image Location in MySQL
Sashi, This (likely) means you have a some generic page (i.e., picture.php) that displays some picture. The picture it displays depends on the parameter passed when the page is called (i.e., 123). Sashi's Test Page ", $row['firstname']); } //Clean up mysql_free_result($output); ?> Please note, I haven't tried this. It just seems plausible. Good luck. A- -Original Message- From: Sashikanth Gurram [mailto:sashi...@vt.edu] Sent: Sunday, March 01, 2009 10:27 PM To: php-db@lists.php.net Subject: [PHP-DB] Retrieving Image Location in MySQL Dear All, I am trying to retrieve the location of a image (not the image, just the location of the image) stored on MySQL database, using PHP to display it in my browser. One of the users has been kind enough to provide me with an example code as to how to do it. He asked me to use / /in the html code. I understood the part of /picture.php? /which tells us that the php code used to retrieve the image is located in the file picture.php (If what I have understood is correct). But I did not quite understand the second part /&qry=123 /. What does this mean? Of what use is this second part? Does the variable &qry has something assigned to it in the picture.php code? I would greatly appreciate it if any one of you can answer my questions. Thanks, Sashi -- ~ ~ Sashikanth Gurram Graduate Research Assistant Department of Civil and Environmental Engineering Virginia Tech Blacksburg, VA 24060, USA -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Re: session variable in select query showing picture from database
Mika, Echo out the dynamically created SQL statement ie., $query = "SELECT * FROM MyTable WHERE ID = ${ID}"; ECHO $query;" Let us see what is actually being passed. P.S. I couldn't agree more with the poster that said, don't pass user input directly to a SQL statement. -Original Message- From: Mika Jaaksi [mailto:mika.jaa...@gmail.com] Sent: Thursday, February 12, 2009 5:02 PM To: php-db@lists.php.net Subject: [PHP-DB] Re: session variable in select query showing picture from database *Answer to Rick: in your code below it looks like you're simply hard-coding your "$band_id" value (as "11") -- so of course it's going to work. *Yes, I did that because one of you helpers asked me to try that. I'll try to be clearer on whom I'm answering to... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Re: session variable in select query showing picture from database
Mika, Put the dollar sign (i.e., $) outside the curly brace. $query="SELECT * FROM pic_upload WHERE band_id='${band_id}'"; A- -Original Message- From: Mika Jaaksi [mailto:mika.jaa...@gmail.com] Sent: Thursday, February 12, 2009 12:27 PM To: php-db@lists.php.net Subject: [PHP-DB] Re: session variable in select query showing picture from database Still fighting with it... So, these work: $query="SELECT * FROM pic_upload; $query="SELECT * FROM pic_upload WHERE band_id=11"; picture is shown on the other page but when adding variable into query it doesn't show the picture on the other page $query="SELECT * FROM pic_upload WHERE band_id='{$band_id}'"; I'm out of ideas at the moment... ps. forget what I said about the weird markings... 2009/2/12 Mika Jaaksi > I'm trying to show picture from database. Everything works until I add > variable into where part of the query. > > It works with plain number. example ...WHERE id=11... ...picture is shown > on the page. > > Here's the code that retrieves the picture. show_pic.php > > function db_connect($host='', $user='', > $password='', $db='') > { > mysql_connect($host, $user, $password) or die('I cannot connect to db: ' . > mysql_error()); > mysql_select_db($db); > } > db_connect(); > $band_id = $_SESSION['session_var']; > $query="SELECT * FROM pic_upload WHERE band_id=$band_id"; > $result=mysql_query($query); > while($row = mysql_fetch_array($result)) > { > $bytes = $row['pic_content']; > } > header("Content-type: image/jpeg"); > print $bytes; > > > exit (); > mysql_close(); > ?> > > > other page that shows the picture > > echo ""; > ?> > > Any help would be appreciated... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] MySQL Conditional Trigger
All, Chris makes a good point i.e., "unknown compared to anything is unknown". His comment made me want to clarify my earlier note. In my earlier example, I wasn't suggesting that-that logic be coded in the database. I was assuming it would be in the page: I tested this, and it worked. Here is why, PHP (like pretty much every other language) silently casts a NULL to false: "When converting to boolean, the following values are considered FALSE: - the boolean FALSE itself - the integer 0 (zero) - the float 0.0 (zero) - the empty string, and the string "0" - an array with zero elements - an object with zero member variables (PHP 4 only) - the special type NULL (including unset variables)" ("Booleans", php.net, 05 Dec. 2008). If you were going to code it in the database, I'd suggest something like this: --Using T-SQL here... DECLARE @TestNullValue SMALLDATETIME SET @TestNullValue = NULL If (@TestNullValue Is Null) PRINT 'Evaluates to true!'; ELSE PRINT 'Evaluates to false!'; In either case, this should have the same net result. Be Well, A- -Original Message- From: Chris [mailto:[EMAIL PROTECTED] Sent: Monday, December 08, 2008 5:10 PM To: OKi98 Cc: php-db@lists.php.net Subject: Re: [PHP-DB] MySQL Conditional Trigger > anything compared to NULL is always false Actually it's null. mysql> select false = null; +--+ | false = null | +--+ | NULL | +--+ 1 row in set (0.01 sec) mysql> select 1 = null; +--+ | 1 = null | +--+ | NULL | +--+ 1 row in set (0.00 sec) mysql> select 2 = null; +--+ | 2 = null | +--+ | NULL | +--+ 1 row in set (0.00 sec) unknown compared to anything is unknown. -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] MySQL Conditional Trigger
Dee, If all you're trying to code is that a value of NULL equates to FALSE and a date value (whatever date value) equates to true, you can use something like this: If ($MyVariable) { //... true path blah... } else { //... false path blah... } You can use this because NULL equates to false. If you prefer something more concise, try the following: $MyVariable ? //True : //False I'm not a PHP guy so take this with a grain of salt. If I'm full of it, don't hesitate to correct me. A- -Original Message- From: OKi98 [mailto:[EMAIL PROTECTED] Sent: Monday, December 08, 2008 4:33 PM To: Dee Ayy Cc: php-db@lists.php.net Subject: Re: [PHP-DB] MySQL Conditional Trigger Original Message Subject: [PHP-DB] MySQL Conditional Trigger From: Dee Ayy <[EMAIL PROTECTED]> To: php-db@lists.php.net Date: 31.10.2008 17:09 > I don't think my trigger likes a comparison with a variable which is > NULL. The docs seem to have a few interesting variations on playing > with NULL and I was hoping someone would just throw me a fish so I > don't have to try every permutation (possibly using CASE, IFNULL, > etc.). > > If my ShipDate (which is a date datatype which can be NULL) changes to > a non-null value, I want my IF statement to evaluate to TRUE. > IF NULL changes to aDate : TRUE > IF aDate changes to aDifferentDate : TRUE > IF anyDate changes to NULL : FALSE > > In my trigger I have: > ... > IF OLD.ShipDate != NEW.ShipDate AND NEW.ShipDate IS NOT NULL THEN > ... > > Which only works when ShipDate was not NULL to begin with. > I suppose it evaluates the following to FALSE > IF NULL != '2008-10-31' AND '2008-10-31' IS NOT NULL THEN > (not liking the "NULL != '2008-10-31'" part) > > Please give me the correct syntax. > TIA > > anything compared to NULL is always false NULL = NULL (NULL included) => false NULL != anything (NULL included) => false that's why IS NULL exists I would go this way: IF NVL(OLD.ShipDate, -1) != NVL(NEW.ShipDate, -1) THEN -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Re: MS SQL error...I've come a long way to get this far
Fred, If you're using integrated security (e.g., a domain account such as "domain\bob"), you won't supply a password. However, the "sa" account is a SQL login (v.s. a domain login). In that case, it would make sense that you supply a password. See the following page for some code to connect using integrated security: http://msdn.microsoft.com/en-us/library/cc296205(SQL.90).aspx See the following page for some code to connect using a SQL login: http://msdn.microsoft.com/en-us/library/cc296182(SQL.90).aspx If you're curious if this is even an authentication/permissions issue, try to login using a domain login. The login event will be recorded in the `Event Viewer`. If you're attempt isn't recorded, you've got a communication problem with the server instance. If it is recorded, you'll be able to tell what the problem is authenticating. Good luck, and let us know how it turns out. A- -Original Message- From: Fred Silsbee [mailto:[EMAIL PROTECTED] Sent: Monday, December 08, 2008 3:30 PM To: php-db@lists.php.net Subject: [PHP-DB] Re: MS SQL error...I've come a long way to get this far I was just thinking about something I've never understood completely! mssql_connect($server, 'sa', 'PW'); presumes the server doesn't have all the permissions in spite of the fact that it has the password. The password I gave is the XP Prof login PW. Maybe some other PW. --- On Mon, 12/8/08, Fred Silsbee <[EMAIL PROTECTED]> wrote: > From: Fred Silsbee <[EMAIL PROTECTED]> > Subject: MS SQL error...I've come a long way to get this far > To: php-db@lists.php.net > Date: Monday, December 8, 2008, 7:13 PM > many changes to php.ini to get this far..whew! > > PHP 5.2.7 just got jerked out from underneathe me (I > have't replaced it since this is a simple script) > > phpinfo works! > > // Server in the this format: > \ or > // , when using a non default > port number > $server = 'LANDON\SQLEXPRESS'; > > $link = mssql_connect($server, 'sa', 'PW'); > < line 6 > > if(!$link) > { > die('Something went wrong while connecting to > MSSQL'); > } > ?> > > > Warning: mssql_connect() [function.mssql-connect]: Unable > to connect to server: LANDON\SQLEXPRESS in > C:\Inetpub\wwwroot\trymssql.php on line 6 > Something went wrong while connecting to MSSQL -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] re:database tables relations advice
Mr. Froasty, >From your note, it sounds like you want to use foreign keys; as Daniel pointed out. I think an example would be helpful here. The subject of foreign keys is bigger than a bread box so I'll just touch on the pieces I think you'll find helpful. There is all sorts of literature scattered about the web if you want to know more. Let's start with a fictional case: I work for a company with multiple departments each of which have one or more employees. I would like a relational data structure to capture departmental and employee information as well as preserve the relationship between the two. Make sense? I create two tables: `Department` and `Employee`. Each table has a primary key (as you illustrated in your example), which is unique per record. I add a column in Employee that holds the primary key of the employee's associated department. I then create a relation between the two tables to indicate there is a relationship. --Create the Department table CREATE TABLE Department ( IDDepartment INT NOT NULL AUTO_INCREMENT, Name VARCHAR(35), PRIMARY KEY (IDDepartment) ) ENGINE = InnoDB; --Create the Employee table and simultaneously the --relation to Department CREATE TABLE Employee ( IDEmployee INT NOT NULL AUTO_INCREMENT, idDepartment INT NOT NULL, Name VARCHAR(35), PRIMARY KEY (IDEmployee), INDEX IDX_idDepartment (idDepartment), FOREIGN KEY (idDepartment) REFERENCES Department(idDepartment) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE = InnoDB; MySQL can do all of this provided you're using the InnoDB storage engine. MySQL's documentation has some helpful information on the subject - see link below. http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-foreign-keys.html With me so far? A few points specific to MySQL: (1) Whatever field you chose as your foreign key, needs an index. (2) You can add foreign keys after a table has been created using an ALTER statement. (3) The option ON DELETE CASCADE means that whenever the parent record (i.e., the department) is deleted the related employees will be deleted too. (4) The option ON UPDATE CASCADE means that whenver the parent's key record (i.e., the department) is updated the related foreign key record will be updated too. (5) There are options other than ON UPDATE and ON DELETE. Give'm a look. Good luck, and welcome to the DB development club. Cheers, Adam -Original Message- From: mrfroasty [mailto:[EMAIL PROTECTED] Sent: Thursday, November 27, 2008 5:19 AM To: php-db@lists.php.net Subject: [PHP-DB] re:database tables relations advice I am quite new to database designs, I have a problem in my design...I can actually feel it, but I am not quite sure if there is a feature in mysql or I have to solve it with programming. Example: CREATE TABLE A ( user_id int(16) NOT NULL auto_increment, ..other datas PRIMARY KEY (user_id) ); CREATE TABLE B ( user_id int(16) NOT NULL auto_increment, ..other datas PRIMARY KEY (contact_id) ); Question: How can I declare that the user_id in my 1st table is related to user_id in the 2nd table...actually I prefer to have it exactly the same user_id in both tablesI think if those 2 entries are the same it will be great, but I am not sure how to achieve this. P:S -Ofcourse I know that I can extract it from TABLE A and save it in TABLE Bbut is that a way to go???Because this issue arise in couple of tables in my data structure that I am tending to use in my application(web). -I also know that its possible to make just 1 big table with lots of columnsbut I read its not a good database design... ->please advice, running out of ideas :-( Thanks.. -- Extra details: OSS:Gentoo Linux-2.6.25-r8 profile:x86 Hardware:msi geforce 8600GT asus p5k-se location:/home/muhsin language(s):C/C++,VB,VHDL,bash Typo:40WPM url:http://mambo-tech.net -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Unable to Login to Oracle 9i-R2 Database Using PHP 5.2.5
Chris/Rick/Neil, I put together a test page (test.php) with content . When the page is displayed, I don't see anything related to OCI8. To Rick's point, the module isn't being uploaded. I believe I know why it isn't loading. I don't believe the ISAPI PHP module is loading the right PHP.ini (ini) file. When I run php at the CLI, it loads the ini in the same directory as PHP's executable (c:\php\) i.e., it loads c:\php\php.ini. C:\>php --ini Configuration File (php.ini) Path: C:\WINDOWS Loaded Configuration File: C:\PHP\php.ini Scan for additional .ini files in: (none) Additional .ini files parsed: (none) When I look at the php information displayed by my test page, it looks like php is looking for an ini-file in the C:\Windows\ directory. Configuration File (php.ini) Path -> C:\WINDOWS Loaded Configuration File -> (none) This gets better. When process the page on the CLI (e.g., php -f ), it processes without an issue. As stated before, it (the same page) fails when processed thru IIS. I need to do some more work to get this fixed, but your comments were a big help. Thanks! A- -Original Message- From: Chris [mailto:[EMAIL PROTECTED] Sent: Monday, November 24, 2008 5:54 PM To: Fortuno, Adam Cc: php-db@lists.php.net Subject: Re: [PHP-DB] Unable to Login to Oracle 9i-R2 Database Using PHP 5.2.5 > Rick, when I delve into the php_info() shmaz, I see this snipet - see > below. I'm not sure if I should be looking for something else or not. Try doing this from a web page. Maybe it has a different php.ini or something. Anything in the IIS error log (probably goes to the windows logs) ? -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Unable to Login to Oracle 9i-R2 Database Using PHP 5.2.5
Chris/Rick, Thank you both for the notes. I sincerely appreciate the help. Chris, I've got a "php_oci8.dll" file sitting in my extensions directory (C:\php\ext) - see below. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- =-=-=-= Console Output =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- =-=-=-= C:\PHP\ext>dir Volume in drive C has no label. Volume Serial Number is 84DF-21C4 Directory of C:\PHP\ext 11/24/2008 02:59 PM . 11/24/2008 02:59 PM .. 11/08/2007 11:23 PM41,019 php_crack.dll 11/08/2007 11:23 PM28,732 php_ntuser.dll 11/08/2007 11:23 PM 102,458 php_oci8.dll 3 File(s)172,209 bytes 2 Dir(s) 40,158,838,784 bytes free =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- =-=-=-= As best I can tell, I've correctly set my extensions directory (C:\php\ext) and I've called the oci8 DLL correctly - see below. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- =-=-=-= php.ini Snipet =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- =-=-=-= C:\PHP\ext>type ..\php.ini | grep -in php_oci 1293:[PHP_OCI8] 1294:extension=php_oci8.dll C:\PHP\ext>type ..\php.ini | grep -in \\ext 536:extension_dir ="C:\PHP\ext" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- =-=-=-= Let me know if I've mucked that up. Rick, when I delve into the php_info() shmaz, I see this snipet - see below. I'm not sure if I should be looking for something else or not. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- =-=-=-= PHP information =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- =-=-=-= C:\PHP\ext>php -i ...stuff... oci8 OCI8 Support => enabled Version => 1.2.4 Revision => $Revision: 1.269.2.16.2.38 $ Active Persistent Connections => 0 Active Connections => 0 Temporary Lob support => enabled Collections support => enabled Directive => Local Value => Master Value oci8.default_prefetch => 10 => 10 oci8.max_persistent => -1 => -1 oci8.old_oci_close_semantics => 0 => 0 oci8.persistent_timeout => -1 => -1 oci8.ping_interval => 60 => 60 oci8.privileged_connect => Off => Off oci8.statement_cache_size => 20 => 20 ...other stuff... =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- =-=-=-= If I take the page that is generating the error and move it to my Redhat box running PHP 5.0.2, I have no problem. If I use it locally, I get the error. What am I missing here? Cheers, A- -Original Message- From: Chris [mailto:[EMAIL PROTECTED] Sent: Monday, November 24, 2008 4:56 PM To: Fortuno, Adam Cc: php-db@lists.php.net Subject: Re: [PHP-DB] Unable to Login to Oracle 9i-R2 Database Using PHP 5.2.5 > //Return the database connection > OCILogon($username, $passwd, $db); > > I receive an error stating, "Fatal error: Call to undefined function > OCILogon() in C:\Documents and Settings\afortuno\My > Documents\Dev\DBAIntranet\ghr_resources\transaction_report\adam.php on > line 7" > The error message couldn't be more vague, and I'm not experienced enough > with Oracle, IIS, or PHP to know where to turn for more insight. Any > help would be appreciated. The error is pretty clear. You're trying to call a function that doesn't exist. Tracing it backwards, the php_oci.dll (or php_oci8.dll) isn't being loaded. Search for oci8 here: http://pecl4win.php.net/ and grab the dll file. There are some notes http://www.php.net/manual/en/install.windows.extensions.php about how to install this. -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Unable to Login to Oracle 9i-R2 Database Using PHP 5.2.5
All: I'm running PHP in ISAPI mode with IIS accessing (or attempting to access) an Oracle 9i database on a RedHat box. Here are the versions of everything: Web Server: IIS v5.1 PHP: 5.2.5 Database: ORACLE v9i-R2 I am attempting to load a page with the following code: //Database credentials $username = "MyUser"; $passwd = "MyPassword"; $db="DBName"; //Return the database connection OCILogon($username, $passwd, $db); I receive an error stating, "Fatal error: Call to undefined function OCILogon() in C:\Documents and Settings\afortuno\My Documents\Dev\DBAIntranet\ghr_resources\transaction_report\adam.php on line 7" I'm able to use SQL Plus to login to the database I'm interested in. This gives me the impression that my credentials are not the problem; however, the plumbing between PHP and Oracle is the culprit. I initially had problems loading the OCI extension DLL. I resolved the issue by installing the Oracle 10g instant client. Here are the steps I followed as part of that process: (1) Download Oracle Instant Client Package Basic (v10.2.0.4) for Win32 http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/ winsoft.html (2) Unzip the contents downloaded zip-file. (3) Move the folder to the "C:\Oracle" directory. (4) Add the new folder (C:\oracle\ora102ic) to the PATH. (5) Restart IIS (e.g., C:\> iisreset). The error message couldn't be more vague, and I'm not experienced enough with Oracle, IIS, or PHP to know where to turn for more insight. Any help would be appreciated. Cheers, Adam