Re: [PHP-DB] One query, different tables?

2013-08-09 Thread Niel Archer
> Hello.
> I am newbie in this and need som basic help.
> 
> I have a form witch checkbox'es with different serialnumbers.
> The serialnumbers reflect different products and every product category
> have their own tables.

This sounds like a database design question more than a PHP one.

> 
> I can transfer items from store to truck but can't transfer them back to
> store.
> I have 4 stores and like to transfer products between this.
> 
> I like to to it like this:
> store_one -> truck_document -> store_two
> 
> But how can I transfer both Dynamite and Exan in one query to their
> respective tables? (One table is named exan and the other dynamite.)
> 
> Thank you very much for your help.
> 
> I have been searching google but can't find anything about this question.
> 
> Karl

--
Niel Archer
niel.archer (at) blueyonder.co.uk


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



Re: [PHP-DB] PDO Exceptions

2013-04-25 Thread Niel Archer
> Greetings,
> 
> I am new to this list. I have a question about which functions need to be 
> included in a try block. 
> 
> Of "new PDO", "prepare", "bindParam", "execute", "fetch", and "query", it 
> seems that bindParam is the only one that throws an exception. So is this the 
> only that needs to be put into a try block?
> 
> Thanks,
> 
> -KJW
> Proverbs 3:5-6

Are you aware that there is a setting to control whether PDO objects throw
exceptions, warnings, or nothing? By default it does nothing except set
the error code and message.

See http://uk3.php.net/manual/en/pdo.error-handling.php

--
Niel Archer
niel.archer (at) blueyonder.co.uk


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



Re: [PHP-DB] Activating the mysql_clear_password plugin

2012-09-27 Thread Niel Archer
Hi
> 
> You could try using mysqli_options(), but I do not know if that supports
> this setting yet. The PHP documentation does not mention it, and I am
> unable to test it myself at the moment.

Just occured to me, even if the setting is not directly supported yet, you
can create a separate configuration file for this setting the client to
use the plugin (enable-cleartext-plugin) then:

mysqli_options(MYSQLI_READ_DEFAULT_FILE,'myother.cnf');

to use those settings on the connection.


--
Niel Archer
niel.archer (at) blueyonder.co.uk


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



Re: [PHP-DB] Activating the mysql_clear_password plugin

2012-09-27 Thread Niel Archer
> Hi everyone,
> 
> I need to use the mysql_clear_password plugin.
> I'm using the CentOS php 5.3.3 and manually recompiled the mysql & 
> mysqli extensions with the Oracle MySQL 5.5 libraries.
> 
> According to the MySQL documentation ( 
> http://dev.mysql.com/doc/refman/5.5/en/cleartext-authentication-plugin.html), 
> I need to either set the LIBMYSQL_ENABLE_CLEARTEXT_PLUGIN or set the 
> MYSQL_ENABLE_CLEARTEXT_PLUGIN option to the mysql client.
> 
> I tried to set the LIBMYSQL_ENABLE_CLEARTEXT_PLUGIN via a SetEnv in 
> Apache with no results.

The SetEnv directive sets variables for Apache's internal environment.the
 I believe the MySQL docs are refering to the Operating System's
environment, which would set this globally for the MyQL server. This is
probably not what you want to do as you appear to be trying to do this
per connection.

You could try using mysqli_options(), but I do not know if that supports
this setting yet. The PHP documentation does not mention it, and I am
unable to test it myself at the moment.

> Could anyone help me setting the MYSQL_ENABLE_CLEARTEXT_PLUGIN option to 
> the mysql client ?
> 
> Regards,
> 
> Pierre-Gildas MILLON
> pg.mil...@gmail.com
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--
Niel Archer
niel.archer (at) blueyonder.co.uk


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



Re: [PHP-DB] Storing multiple items in one MySQL field?

2012-01-18 Thread Niel Archer
ql_fetch_assoc($result);
>   extract($row);
>   
>   //this is where I am trying to extract and order the colors and sizes.
>   if(mysql_num_rows($row['colorid']) >1) {
>   foreach($row['colorid'] as $color) {
>   ... //fetch each size for $color
>   } else {
>   ... //Get size for only color
>   }
> 
>   $row['pd_description'] = nl2br($row['pd_description']);
>   
>   if ($row['pd_image']) {
>   $row['pd_image'] = PRODUCT_IMAGE_DIR . $row['pd_image'];
>   } else {
>   $row['pd_image'] = WEB_ROOT . 'images/no-image-logo.png';
>   }
>   
>   $row['cart_url'] = WEB_ROOT."cart.php?action=add&p=".$pdId."";
>   
>   return $row;
> }
> 
> TIA
> 
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--
Niel Archer
niel.archer (at) blueyonder.co.uk


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



Re: [PHP-DB] Receiving Error- Error: user account already exists..

2012-01-10 Thread Niel Archer
> I keep receiving the following error..( Error: user account already exists..
> ) although I don't have any data in my table. Any help would be appreciated.
> 
> The code follows:
> 
>  
> 
>  
> 
>  
> session_start();
> 
>  
> 
>  
> 
> include ('dbc.php'); 
> 
>  
> 
>  
> 
>  
> 
> if (isset($_POST['Submit']) =='Register')

As Jim already pointed out, if $_POST['Submit'] is set to ANY value this
check will be true. I think you want something like :

if (isset($_POST['Submit']) && $_POST['Submit'] =='Register')

> {
>if (strlen($_POST['email']) < 5)
>{
> die ("Incorrect email. Please enter valid email address..");
> }
>
>if (strcmp(isset($_POST['pass1']),isset($_POST['pass2'])) ||
> empty($_POST['pass1']) )
> { 
> //die ("Password does not match");
> die("ERROR: Password does not match or empty..");
> }
> 
> if (strcmp(md5($_POST['user_code']),$_SESSION['ckey']))
> { 
>  die("Invalid code entered.
> Please enter the correct code as shown in the Image");
>   } 
> 
> $rs_duplicates = mysql_query("select id from users where
> user_email='$_POST[email]'");

You should test $rs_duplicates !== false to be sure you have a valid
resource.

Have you tried retrieving the supposed row(s) and var_dump-ing them to
see what it thinks they are? My guess is, you're getting an error
message, which is why there is a row to be counted. You can't use an
array inside a double-quoted string like that, change it to be wrapped
in braces like:

 $rs_duplicates = mysql_query("select id from users where user_email='
{$_POST[email]}'");


--
Niel Archer
niel.archer (at) blueyonder.co.uk


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



Re: [PHP-DB] Storing multiple items in one MySQL field?

2012-01-07 Thread Niel Archer

--
Niel Archer
niel.archer (at) blueyonder.co.uk
> Hello phpers and sqlheads,
> If you have a moment, I have a question.
> 
> INTRO:
> I am trying to set up categories for a web site.
> Each item can belong to more than one category.
> 
> IE: Mens, T-Shirts, Long Sleeve Shirts, etc.. etc..
> (Sorry no fancy box drawing)
> 
> QUESTION:
> My question is what would the best way be to store this in one MySQL  
> field and how would I read and write with PHP to that field?
> I have thought of enum() but not on the forefront of what that  
> actually does and what it is best used for.
> I just know its a type of field that can have multiple items in it.  
> Not sure if its what I need.
> 
> REASON:
> I just want to be able to query the database with multiple category  
> ID's and it check this field and report back if that category is  
> present or if there are multiple present.
> Maybe return as a list or an array? I would like to stay away from  
> creating multiple fields in my table for this.

Have you considered separate tables? Store the categories in one table
and use a third to store the item and category combination, one row per
item,category combo. This is a common pattern  to manage such situations.

> NOTE:
> The categories are retrieved as a number FYI.
> 
> Any help/code would be greatly appreciated.
> But a link does just fine for me.
> 
> Best Regards,
> 
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
> 
> Hope your all enjoying your 2012!


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



Re: [PHP-DB] problem in connecting to mysql from php

2011-06-14 Thread Niel Archer

> Hello everyone,
> 
> I am in the process of learning php and I was trying to connect to a mysql
> database on my own computer(localhost). I have done the following as
> prerequisites:
> 
> copied the dll files in system32
> removed the semicolon(;) from extension=php_mysqli.dll

You should NOT need to move the .dll at all. There is a
setting in the ini which tells PHP where to look for extensions and that
should have pointed to the original location. Hence, removing the
semicolon should be the only part necessary.

> In spite of doing the above when I try to run the following :
> 
>  $db = new MySQLi('localhost', 'root', 'Password123', 'test');
> $sql = 'SELECT * FROM a123';
> $result = $db->query($sql);
> 
> while($row = $result->fetch_object()) {
> echo '' . $row->name . '';
> }
> 
> $db->close();
> ?>
> 
> I get the error: *Fatal error*: Class 'MySQLi' not found in *C:\Program
> Files\Apache Software Foundation\Apache2.2\htdocs\a.php* on line *2
> 
> *Please guide me as to how can I get rid of this error?
> 
> Regards,
> Kushal



--
Niel Archer
niel.archer (at) blueyonder.co.uk


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



Re: [PHP-DB] mysql_query

2011-06-06 Thread Niel Archer
> Hello all,
> 
> Not sure what I am doing wrong.
> 
> I have a simple form that populate the variables in a mysql query. I
> know the selected values are making it to the form porcessing script
> because I can echo them on the processing script as indicated below.
> 
> You Selected Cell_Sect = 1_1
> You Selected Date = 03/10/11 18:15
> You Selected Market = MCI
> 
> For some reason the above is all I am getting when I submit my form.
> 
> I beleive it has somthing to do with my results query below.
> 
> $result = mysql_query("select * FROM evdo WHERE Market like '%$term'
> and Cell_Sect = '$cat' and Date = '$subcat' LIMIT 10");
> 
> Beow is my whole script for processing the form in case it maybe something 
> else.
> 
> Thanks,
> 
> Chris
> 
> 
> 
> 
> 
>  
> // database access parameters
> $dbservertype='mysql';
> $servername= left out for privacy;
> // username and password to log onto db server
> $dbusername='';
> $dbpassword='';
> // name of database
> $dbname='pcmd';
> 
> connecttodb($servername,$dbname,$dbusername,$dbpassword);
> function connecttodb($servername,$dbname,$dbuser,$dbpassword)
> {
> global $link;
> $link=mysql_connect ("$servername","$dbuser","$dbpassword");
> if(!$link){
> die('Could not conect: ' . mysql_error());
> }
> echo 'YOU ARE CONNECTED TO PCMD DATABASE';
> 
> mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}  <- What's this doing here
>  End of connecting to database 
> ?>
>  'http://www.w3.org/TR/xhtml1-transitional.dtd'>
> 
> Demo Multiple drop down list box for PCMD data
> 
>   TABLE {
>  border: 1px solid #98bf21;
>  border-collapse:collapse;
>   }
> 
>   TH {
>  border: 1px solid #98bf21;
>  padding-bottom: 4px;
>  padding-left: 7px:
>  padding-right: 7px;
>  padding-top: 5px;
>  font-size: 1.2em;
>  background-color:limegreen;
>  color: white;
>  text-align: left;
>   }
> 
>   TD {
>  border: 1px solid #98bf21;
>  padding-bottom: 2px;
>  padding-left: 7px:
>  padding-right: 7px;
>  padding-top: 3px;
>  font-size: 1.0em;
>   }
> 
>   TR.alt TD {
>   background-color: #eaf2d3;
> 
>   }
> 
> 
> 
> 
> 
> 
> 
>  $cat=$_POST['cat'];
> $subcat=$_POST['subcat'];
> $term=$_POST['term'];
> 
> $result = mysql_query("select * FROM evdo WHERE Market like '%$term'
> and Cell_Sect = '$cat' and Date = '$subcat' LIMIT 10");
> 
> 
> $firstRow=1;
> $rowNum = 0;
> echo "";
> while($row = mysql_fetch_assoc($result)) {
>if($firstRow == 1) {
>   echo "";
> 
>   foreach($row as $key => $value) {
>   echo "" . $key . "";
>   }
>   echo "";
>   $firstRow=0;
>   $rowNum++;
>}
>else {
>   if(  ($rowNum++ % 2) == 1) {
>  echo "";
>   } else {
>  echo "";
>   }
>}
>foreach($row as $key => $value ) {
>echo "" . $value . ""  ;
>}
>echo "";
> }
> echo "";
> 
> echo "You Selected Cell_Sect = $cat You Selected Date =
> $subcatYou Selected Market = $term";
> 
> 
> ?>
> 
> 
> 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

After your mysql_select_db() there is a closing brace without matching
open. This will be causing an error in that php block.

--
Niel Archer
niel.archer (at) blueyonder.co.uk


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



Re: [PHP-DB] Can't find sqlite_open

2011-01-08 Thread Niel Archer
> Hello,
> I have a script that is calling sqlite_open, however, sqlite_open can't be 
> found on my systems. I'm running RHEL5 and I get the following relevant 
> output from php -i:
> 
> PDO support => enabled
> PDO drivers => odbc, sqlite
> 
> pdo_sqlite
> 
> PDO Driver for SQLite 3.x => enabled
> PECL Module version => 1.0.1 $Id: pdo_sqlite.c,v 1.10.2.6 2006/01/01 
> 12:50:12 sniper Exp $
> SQLite Library => 3.3.6
> 
> From searching around, it seems like there is a PDO version, which looks to 
> be enabled here, and a older version, which would provide sqlite_open. Is 
> that correct?

sqlite_open is not a PDO statement. It belongs to the PECL SQLite
extension. This extension is quite old and is superseded by the SQLite3
extension and/or PDO.


> Thanks! 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] Re: Word Activity Application

2011-01-03 Thread Niel Archer
> 
> The FOREACH below is giving me the error:
> Invalid argument supplied for foreach()

Not surprising as the $match_words will contain a boolean result from
shuffle. Shuffle works directly on the variable it is given and returns
true or false, depending on success. rtfm ;-)

> Does anyone understand what I have done to cause this error?
> 
> #query for words
> 
> $query = "
> SELECT `reference` , `word` , `explanation` 
> FROM `Bible_dictionary` 
> WHERE `live` =1
> ORDER BY RAND( ) 
> LIMIT 5
> ";
> $words_match_up_result=mysql_query($query);
> $records_found=mysql_numrows($words_match_up_result);
> 
> echo $records_found . ""; # output is 5
> 
> #create array from mySQL query
> 
> $words = array();
> $explanations = array();
> 
> $i=1;
> while ( $i <= $records_found ) {
> 
> $words[$i] = stripslashes( mysql_result($words_match_up_result,($i 
> -1),"word") );
> $explanations[$i] = stripslashes( mysql_result($words_match_up_result,($i 
> -1),"explanation") );
> 
> ++$i;
> }
> 
> #shuffle arrays
> 
> $match_words = shuffle ( $words );
> $match_explanations = shuffle ( $explanations );

change to:
$match_words = $words;
shuffle($match_words);
$match_explanations = $explanations;
shuffle($match_explanations);

However if these need to stay in sync this will not work. i.e if a
explanation's index needs to match the corresponding word's index, then
you'll have to do this another way. But as I understand your need here,
this isn't a problem?

> #display words on the screen
> 
> foreach($match_words as $word) {
> 
> echo $word . "\r\n";
> 
> }
> 
> The Verse of the Day
> “Encouragement from God’s Word”
> http://www.TheVerseOfTheDay.info
> 
> 
> From: Ron Piggott 
> Sent: Sunday, January 02, 2011 5:54 PM
> To: php-db@lists.php.net 
> Subject: Word Activity Application
> 
> 
> I am working on a word activity --- matching words and their definitions.  
> 
> I want to display 5 words on the left hand side and the 5 definitions on the 
> right hand side.  But I want the definitions displayed in a different order 
> than the words so the user submits their answer.  
> 
> Should I use PHP to display the definitions in random order?  OR Is there a 
> way do this in mySQL that would mix and match results from different rows?  
> This is the query gives me the 5 results
> 
> SELECT `reference` , `word` , `explanation` 
> FROM `Bible_dictionary` 
> WHERE `live` =1
> ORDER BY RAND( ) 
> LIMIT 5 
> 
> Ron
> 
> The Verse of the Day
> “Encouragement from God’s Word”
> http://www.TheVerseOfTheDay.info

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] Re: [PHP] Strange Query Error...

2010-11-27 Thread Niel Archer
> On Nov 27, 2010, at 10:08 AM, Daniel P. Brown wrote:
> 
> > one primary question: are you using the mysql_*
> > family, mysqli_* family, or another method of interfacing with MySQL?
> 
> mysql_
> 
> $results = mysql_query($query) or die(mysql_error());
> 
> Don
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
Could you show the actual code, not just the query. The way you are
setting up the query could be affecting it. i.e. using single quotes when
assigning to a variable would not work with your query.

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] If condition in query

2010-11-18 Thread Niel Archer
> Dear list -
> 
> Thank you for all your excellent help.
> 
> I wish to search a table.  In this case, I have five(5) columns: 
> site, Record, BMI, Weight and Height.
> I wish to be able to search on one or more of the columns.  If I use 
> a query like:
> 
> $ste = $_POST['site'];
> $req = $_POST['Record'];
> $wgt = $_POST['Weight'];
> $hgt = $_POST['Height'];
> $bmi = $_POST['BMI'];
> 
> $sql1 =  "select * from  intake2 where site = '$ste' &&  Weight = 
> '$wgt' &&  Record = '$req' &&  '$hgt' = Height &&  '$bmi' = BMI ";
> $result = mysqli_query($cxn, $sql1);
> 
> and do not use all the  variables, no data is returned.  I use to 
> extract the data from the query.
> 
> while($row = mysqli_fetch_array($result[0]))
> 
>  {
>  $site2 = $row[0];
>  $record2 = $row[1];
>  $bmi2 = $row[2];
>  $wgt2 = $row[3];
>  $hgt2 = $row[4];
>  printf("%s\t%d\t%3.1f\t%d\t%d", $site2, $record2, 
> $bmi2, $wgt2, $hgt2);
>  }
> 
> 
> If I put an extra test in the query to exclude blank values;eg, 
> (if(isset ($bmi) &&  '$bmi' = BMI ), $result defaults to a boolean 
> and mysqli_fetch_array($result) fails.  I wish to be able to search 
> on one or more, but not necessarily all, of the parameters and be 
> able to output the results.
> 
> Advice and help please.
> 
> Thanks in advance.
> 
> Ethan

First you need to protect your input from injection and other attacks.
http://en.wikipedia.org/wiki/SQL_injection

for the problem you ask, I'd suggest building the query in php rather
than SQL A simple example would be:

$where ' ';
if (isset($ste)) {
$where .= " site = '$ste'";
}
if (isset($wgt)) {
$where .= ", Weight = > '$wgt'";
}

$sql .= " WHERE $where";


--
Niel Archer
niel.archer (at) blueyonder.co.uk


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



Re: [PHP-DB] query help

2010-11-17 Thread Niel Archer
> Hello PHP Gurus,
> 
> I need your help on an insert query.
> 
> I wanted to know if there is way to insert an array of values into a DB. An
> eg would explain this better :
> 
> If I have 2 tables in a DB, 1) users has 3 columns 2) hobbies = 5 columns
> 
> I was thinking of having a single function which will perform the insert on
> any  insert which happens on the entire website.
> 
> Eg : This function can be called with 2 parameters, the first parameter the
> table name, and the second parameter is an array of values which will be
> inserted into the table.
> eg : Users has these columns [1]ID [2] Name [3]Location
> so the function call would be something like *
> insert_into_tbale(users,array[user_values])*
> **
> Does this make sense ? Is this a good method to follow ?
> 
> Thanks in advance !
> 
> Vinay Kannan.

You don't give any info about the database engine, but assuming you're
using MySQL  take a look at
http://dev.mysql.com/doc/refman/5.0/en/insert.html
Specifically you can use your idea to build an INSERT/VALUE version of
the syntax

INSERT INTO table (col1, col2, .colN.)  VALUES (col1Value1, col2value1,
colNvalue1),  (col1Value2, col2value2, colNvalue2),  ...


--
Niel Archer
niel.archer (at) blueyonder.co.uk


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



Re: [PHP-DB] Parsing Tab Delimited file

2010-10-24 Thread Niel Archer
> Dear list -
> 
> Thanks for all your help.
> 
> I have a tab delimited file which I wish to import into a data 
> base.  In MySQL I can use the LOAD DATA command.  As far as I know, 
> that command cannot be used in PHP as a mysqli_query.  As I 
> understand, I have to parse the file and use the INSERT command.

It can be done, IF the MySQL server allows you to do it.. Check the
servers configuration.

> How do I do it?  Code samples, please.
> 
> Thanks.
> 
> Ethan
> 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] Stuck in apostrophe hell

2010-08-02 Thread Niel Archer
> Before I send the following SQL to MySQL from PHP I print it to screen. 
> PHP chokes on it, but I can paste the exact same query from the screen 
> directly to MySQL and it works just fine. For example:
> 
> Here's the relevant PHP code:
> ==
> $sql_insert_registration = sprintf("INSERT INTO
>   Registrations (
> Class_ID,
> prid,
> Registrant,
> Company,
> Phone,
> Email
>   )
> VALUES (
> $_POST[Class_ID],
> $_POST[prid],
> '%s',".
> parseNull($_POST['Company']).",
> '$_POST[Phone]',
> '$_POST[Email]'
> )", mysql_real_escape_string($_POST['Registrant']));
> 
> echo "".$_POST["Registrant"]."";
> echo "".mysql_real_escape_string($_POST["Registrant"])."";
> echo "".$sql_insert_registration."";
> 
> if (!mysql_query($sql_insert_registration, $con)) { 
>   die('Error: ' . mysql_error()); 
> 
> ==
> 
> 
> Here's the output:
> ===
> 
> INSERT INTO
>   Registrations (
> Class_ID,
> prid,
> Registrant,
> Company,
> Phone,
> Email
>   )
> VALUES (
> 355,
> 257,
> 'Brian O\'Brien',NULL,
> '612-456-5678',
> 'paul_s_john...@mnb.uscourts.gov'
> )
> Error: You have an error in your SQL syntax; check the manual that 
> corresponds to your MySQL server version for the right syntax to use near 
> 'Brien', 'Class registration confirmation', ' This email ' at line 16
> ==
> 
> 
> Also very oddly if the name "O'Brien" is input into the HTML form with two 
> apostrophes side by side (O''Brien) then MySQL will take it (but then of 
> course we have the problem of two apostrophes side by side inserted into 
> the MySQL table). For example:
> 
> ===
> 
> INSERT INTO
>   Registrations (
> Class_ID,
> prid,
> Registrant,
> Company,
> Phone,
> Email
>   )
> VALUES (
> 355,
> 257,
> 'Brian O\'\'Brien',NULL,
> '612-456-5678',
> 'paul_s_john...@mnb.uscourts.gov'
> )
> You have been signed up for the class,
> and a confirmation email has been sent to you.
> =
> 
> Very strange.
> 
> I've checked various PHP variables and cannot figure out. It works fines 
> from another PHP server that's using the same MySQL database.
> 
> Thanks,
> 
> Paul

Probably needs a double backslash for O'Brien. One to escape the
apostrophe and one to escape the backslash escaping the apostrophe. ;-)
This would be because you're not using mysql_real_escape_string() on the
third parameter. Try this (not tested):

$sql_insert_registration = sprintf("INSERT INTO
  Registrations (
Class_ID,
prid,
Registrant,
Company,
Phone,
Email
  )
VALUES (%s, %s, '%s', '%s', '%s', '%s')", 
$_POST[Class_ID],
$_POST[prid],
mysql_real_escape_string(parseNull($_POST['Company'])),
mysql_real_escape_string($_POST[Phone]),
mysql_real_escape_string($_POST[Email]),
mysql_real_escape_string($_POST['Registrant']));


--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] Broken query

2010-07-11 Thread Niel Archer
> 
> I am trying to write a query to select a trivia question, but I don't want
> the trivia question category to be the same two days in a row so I added a
> second "SELECT" syntax to find out what category was used yesterday.  This
> works when I test it "live", but doesn't work when it is part of a cron
> job.  How do I get the value of `Bible_trivia_category_reference` from the
> second SELECT query to be used in the first?  What change is needed?  Ron
> 
> SELECT * FROM `verse_of_the_day_Bible_trivia` WHERE `assigned_date` =
> '-00-00' AND `seasonal_use` = $bible_trivia_application AND `live` =1
> AND NOT `Bible_trivia_category_reference` = ( SELECT
> `Bible_trivia_category_reference` FROM `verse_of_the_day_Bible_trivia`
> WHERE `assigned_date` = '$last_mailing_date' LIMIT 1 ) ORDER BY RAND()
> LIMIT 1

Try changing: "AND NOT `Bible_trivia_category_reference` = ( SELECT ..."
to "AND `Bible_trivia_category_reference` != ( SELECT ..."

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

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] deleting rows with composite primary key

2010-05-18 Thread Niel Archer
> On Tue, May 18, 2010 at 2:51 PM, Niel Archer  wrote:
> >> > Is there a different syntax to the mysql delete statement when the 
> >> > "WHERE"
> >> > clause points only to half of the primary key?
> >> >
> >> > The structure is as follows:
> >> > CREATE TABLE IF NOT EXISTS ` table1` (
> >> >   `id1` int(10) unsigned NOT NULL,
> >> >   `id2` int(10) unsigned NOT NULL,
> >> >   PRIMARY KEY  (`id1`,`id2`),
> >> >   KEY `id2` (`id2`)
> >> > ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
> >> >
> >> > Query is
> >> > $query = "DELETE * FROM table1 WHERE id1 = '$recID';";
> >>
> >> Integer values do not need to be quoted. You should be able to drop the
> >> semi-colon from the query too.  See if that helps
> >>
> >> > Error is a 1064 syntax error.
> >
> > And try var_dump()ing the complete query to make sure it looks as you
> > would expect.
> >
> >
> >> > Any help is appreciated.
> >> >
> >> > Eli
> >> >
> >> >
> >> > --
> >> > PHP Database Mailing List (http://www.php.net/)
> >> > To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >> --
> >> Niel Archer
> >> niel.archer (at) blueyonder.co.uk
> >>
> >>
> >>
> >> --
> >> PHP Database Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >
> > --
> > Niel Archer
> > niel.archer (at) blueyonder.co.uk
> >
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> The syntax should be
> 
> "DELETE FROM table1 WHERE id1 = '$recID';";
> 
> No need for the *

DOH! How did I miss that? Must be time for bed!

> -- 
> 
> Bastien
> 
> Cat, the other other white meat
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] deleting rows with composite primary key

2010-05-18 Thread Niel Archer
> > Is there a different syntax to the mysql delete statement when the "WHERE"
> > clause points only to half of the primary key?
> > 
> > The structure is as follows:
> > CREATE TABLE IF NOT EXISTS ` table1` (
> >   `id1` int(10) unsigned NOT NULL,
> >   `id2` int(10) unsigned NOT NULL,
> >   PRIMARY KEY  (`id1`,`id2`),
> >   KEY `id2` (`id2`)
> > ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
> > 
> > Query is
> > $query = "DELETE * FROM table1 WHERE id1 = '$recID';";
> 
> Integer values do not need to be quoted. You should be able to drop the
> semi-colon from the query too.  See if that helps
> 
> > Error is a 1064 syntax error.

And try var_dump()ing the complete query to make sure it looks as you
would expect.


> > Any help is appreciated.
> > 
> > Eli
> > 
> > 
> > -- 
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> 
> --
> Niel Archer
> niel.archer (at) blueyonder.co.uk
> 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] deleting rows with composite primary key

2010-05-18 Thread Niel Archer
> Is there a different syntax to the mysql delete statement when the "WHERE"
> clause points only to half of the primary key?
> 
> The structure is as follows:
> CREATE TABLE IF NOT EXISTS ` table1` (
>   `id1` int(10) unsigned NOT NULL,
>   `id2` int(10) unsigned NOT NULL,
>   PRIMARY KEY  (`id1`,`id2`),
>   KEY `id2` (`id2`)
> ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
> 
> Query is
> $query = "DELETE * FROM table1 WHERE id1 = '$recID';";

Integer values do not need to be quoted. You should be able to drop the
semi-colon from the query too.  See if that helps

> Error is a 1064 syntax error.
> 
> Any help is appreciated.
> 
> Eli
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] PDO + The Role of PHP + SQLite - Am I missing something?

2010-05-11 Thread Niel Archer
sion to expose functionality that already exists (like that already
> wrapped by PECL php-sqlite3), is insane.

 Agreed. So take your pick of PDO/PDO_sqlite or just SQLite3 extensions.
Both are enabled in PHP 5.3.0 by default, and should be in 5.2 builds
also.

> Am I missing something?

PDO is not needed to access SQLite3. Use the SQLite3 extension; which is
installed by default with PHP 5.3.0.
As noted on the installation instructions for the extension:

Note: This extension was briefly a PECL extension but that version is
only recommended for experimental use.  

So avoid it like the plague and stick with the main extension ;-)
 
> Where do I get involved to help improve the situation?
> 
> All the best,
> Lawrance.
> 
> "Any intelligent fool can make things bigger and more complex...
> It takes a touch of genius - and a lot of courage to move in the
> opposite direction." - Albert Einstein
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] PDOException: could not find driver (postgres)

2010-04-22 Thread Niel Archer
> What could be causing this please? Going direct, using pg_connect, is
> not a problem.

Seems like a simple missing driver problem.  Make sure you have the PDO
postgres driver enabled in your php.ini, it does not use the same driver
as the Postgres extension.

> The code in question looks like
> $pdo = new PDO('pgsql:host=localhost;port=5432;dbname=mydb', 'dbuser',
> 'dbpass');
> (I think - I've yet to be able to debug it down to a single line)



--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] include_path in appache.conf

2010-04-05 Thread Niel Archer
Try asking on the general list. This is not Db related at all, so your
chances of getting answers here are pretty slim.

> This may be an apache question but I'd like to find the php answer first 
> if one exists.
> 
> I have several virtual hosts on a dedicated server. 
> In a IFmodule mod_php5c container in an httpd.conf  include file I have 
> the following to create a unique include path for each virtual host:
> 
> IfModule mod_php5.c>
>   php_value include_path ".:/home/virtual/site#/path/to/include"
>   php_admin_flag safe_mode off
> 
> 
> For one of the virtual hosts I've set up a dev site in a subdomain at 
> dev.site#.com for development.
> In the root directory of this development site I have an .htacces file 
> to create another unique include_path solely for this development subdomain.
> 
> php_value include_path  ".:/home/virtual/site#/path/to/dev/includes"
> 
> Also in the httpd.conf I have
> 
> Allow from all
> AllowOverride All
> Order allow,deny
> 
> 
> 
> The configuration is CentOS 5.3, Apache/2.2.3, PHP 5.1.6
> 
> I recently upgraded the OS from FC6 and the PHP version and I have not 
> been able to get the include_path to change for this dev.subdomain.  
> Even after restarting apache it PHPinfo tells me it is reading the 
> server php.ini and the virtual host include path for the httpd.conf but 
> it is ignoring the .htaccess file. 
> 
> I've even tried putting the php.ini with specific settings in the 
> /home/virtual/site#/root directory to no avail.
> 
> Any ideas how to make this work or even a better set up?
> 
> Thanks in advance.
> 
> 
> 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] PDO include table name prefixes in FETCH_ASSOC

2010-03-24 Thread Niel Archer
> Many of my MySQL tables have columns with the same name.  I want to have 
> PDO include table names in named result sets.  For example:
> 
>$sth = $dbh->prepare("SELECT * FROM table0, table1");
>$result = $sth->fetchAll(PDO::FETCH_ASSOC);
> 
> 
> I want $result to be organized like:
> 
>echo $result["table0.column0"];
>echo $result["table0.column1"];
>echo $result["table1.column0"];
>echo $result["table1.column1"];
> 
> 
> Or, alternatively:
> 
>echo $result["table0"]["column0"];
>echo $result["table0"]["column1"];
>echo $result["table1"]["column0"];
>echo $result["table1"]["column1"];
> 
> 
> Any ideas?  Thanks!

Sounds like you want to UNION two SELECTs
http://dev.mysql.com/doc/refman/5.0/en/union.html

(SELECT col1, col2, col4 FROM table1 WHERE ... ORDER BY ...)
UNION
(SELECT col1, col2, col4 FROM table2 WHERE ... ORDER BY ...)


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

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] Help for a beginner

2009-12-23 Thread Niel Archer
Hi

> Hi everyone, first thank you for ALL help and the understanding that I am new 
> to PHP and MySQL. This is a long email and for that I apologize but I am 
> trying to provide as much detail as possible. If this is the wrong list to 
> ask for help, kindly direct me to the proper authority.
> 
> I am trying to learn and I have built the following environment.
> 
> Windows Server 2008 Standard 32bit service Pack 2 with IIS7
> mysql-essential-5.1.41-win32
> php-5.3.1-nts-Win32-VC9-x86.msi
> phpMyAdmin-3.2.4-english.zip
> 
> 
> I followed the steps as detailed below (I already had IIS7 and CGI installed)
> 
> 
> 1. Install CGI & PHP
>http://www.trainsignaltraining.com/iis-7-install-fastcgi-php/2008-09-04/
> 
> 2. Install MySQL
>http://www.trainsignaltraining.com/install-mysql-on-iis7/2008-09-10/
>
> 3. Install PHPMyAdmin
>
> http://www.trainsignaltraining.com/install-phpmyadmin-on-iis7-and-server-2008/2008-09-16/

This is a bit vague on details. In particular, when installing PHP did
you add the required extensions for MySQL, etc at step 6?
Create a test page containing nothing but this:



Open the page in your browser and verify that mysql, gd, and mbstring
are included.  This will verify that:
1) you added them to your php.ini
and
2) This is the INI file actually being used by the server and not some
random other.

> After I completed the installations
> 1. If I navigate to the PHP directory and type php -info it spews a ton of 
> data at me
>AND
>I created info.php which contains: 
>When I browse this, it correctly produces a page with all the info about 
> my PHP server. Although I do not understand much of it I believe this 
> confirms PHP is working correctly with IIS
> 
> 2. I open the MySQL CLI and perform the commands outlined in Step 23 at this 
> page
>http://www.bicubica.com/apache-php-mysql/index.php
>This returns the expected results, confirming MySQL is working
> 
> 3. PHP is configured to work with php_mysql.dll as per the steps in the 
> trainsignal links above so I begin!
> I go to the phpmyadmin page, enter root and my password and after a long time 
> I get a FastCGI error. I am not ready to believe it because, in classic MS 
> form, it has several VERY different potential causes, and I have covered all 
> of those. Plus the error code is 0x which is like saying nothing... I 
> start thinking maybe it is not connecting to the mYSQL server right, the 
> instructions re: pma and the password made no sense to me so I fiddle with 
> that with no change.
> 
> 
>I  write the mysql_test.php page in step 5 of 
> http://www.bicubica.com/apache-php-mysql/index.php
>This fails with: A connection attempt failed because the connected party 
> did not properly respond after a period of time, or established connection 
> failed because connected host has failed to respond.
> 
>Because the PHP failed I try with ASP...
><%
>set conn=Server.CreateObject("ADODB.Connection")
>conn.ConnectionString="Driver={mySQL};Server=localhost;Database=test;User 
> Id=root;Password=youwish"
>conn.open
>Response.write("Connected")
>conn.close
>%>
> 
>This returns:
>Microsoft OLE DB Provider for ODBC Drivers error '80004005' 
>[Microsoft][ODBC Driver Manager] Data source name not found and no 
> default driver specified 
>/test.asp, line 4
> 
> I believe I have established MySQL is working, but for some reason it appears 
> that it cannot be "reached" This IS on the same server so firewall should not 
> be an issue, PLUS I confirmed the installer did create a hole. I turn off the 
> MS firewall to be safe, no change I try a "repair" of MySQL, I uninstall, 
> reboot and reinstall with no change.
> 
> NOTE: at several points I have tried iisreset and/or rebooting the system 
> with no change.
> 
> I start to research the matter and my mind is now unglued. I found something 
> referencing using mcrypt with PHPMyAdmin to speed it up and wondered if maybe 
> the long delay before the FastCGI error could be resolved so I tracked down 
> the dll, put it in my ext directory and changed my php.ini to reflect this -- 
> file found at http://files.edin.dk/php/win32/mcrypt/
> 
> I found quite a bit about using libmysql.dll but there was no such file in my 
> install, I pulled down the .zip package and that also did not contain it, I 
> eventually found it in a 5.2.x archive but that does not seem to have helped. 
> I have tried enabling: only mysql, mysql AND mysqli, and only mysqli. None of 
> this seems to have done anything to change my situation.
> 
> Again, I a

Re: [PHP-DB] Does PHP5 support querying an MS Access MDE file?

2009-11-03 Thread Niel Archer
> 2009/11/3 Timothy Legg :
> >> 2009/11/2 Timothy Legg :
> >>> Hello,
> >>>
> >>> I have PHP Version 5.2.6-1+lenny3
> >>>
> >>> I have been having difficulty using odbc_connect with an MS Access MDE
> >>> database. Â I do have php5-mysql and php5-odbc installed on this server.
> >>>
> >>> Due to the rather poor search results regarding the topic of querying
> >>> MDE
> >>> files with PHP, I am becoming increasingly concerned that this file type
> >>> is not supported.
> >>>
> >>> Is it possible to query an MDE file via PHP5 or should I try different
> >>> approach to querying the database from our linux server? Â I am
> >>> interested
> >>> in your thoughts.
> >>>
> >>> Thanks for your help.
> >>>
> >>> Tim Legg
> >>>
> >>
> >> If you have the MS Access ODBC driver installed, then have you tried
> >> accessing the MDE as an MDB?
> >>
> >
> > Yes, I have.  The username and password are arbitrarily set since the
> > management hasn't provided that data for me yet.  But I am not far enough
> > along to have run into a user rights issue.  I get a warning and also an
> > error upon interpreting the page.  I have checked the path to the database
> > file, and it is correct.  I also checked file ownership and readability
> > permissions, too.  So maybe the name of the driver is wrong; it does look
> > a little verbose to me, but it did come straight from the php.net online
> > documentation.
> >
> > Error messages and source is below.  Sorry, I modified the domain name in
> > the path for privacy.
> >
> > Warning: odbc_connect() [function.odbc-connect]: SQL error:
> > [unixODBC][Driver Manager]Data source name not found, and no default
> > driver specified, SQL state IM002 in SQLConnect in
> > /var/www/www.example.com/ht-secure/database_entry/test.php on line 9
> >
> >
> >  > $mdbFilename = "/root/tims_db.mde";
> > $user = "root";
> > $password = "1248163264";
> >
> > $connection = odbc_connect("Driver={Microsoft Access Driver
> > (*.mdb)};Dbq=$mdbFilename", $user, $password);
> >
> > ?>
> >
> > Thanks for looking this over,
> >
> > Tim Legg
> >
> >>
> >>
> >> --
> >> -
> >> Richard Quadling
> >> "Standing on the shoulders of some very clever giants!"
> >> EE : http://www.experts-exchange.com/M_248814.html
> >> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> >> ZOPA : http://uk.zopa.com/member/RQuadling
> >>
> >
> >
> >
> 
> You've got odbc, but probably not a driver for MS Access.
> 
> You need both.
> 
> I can't seem to find a unix driver for MSAccess.
> 
> Converting to a different DB would help (mysql, sqlite).

I had a similar problem. I had to access (pardon the pun) a very old MS
Access db. Being on x64 windows ODBC is not an option, so in the end I
used OpenOffice.org with a java driver to open it and copy data to MySQL.

> -- 
> -
> Richard Quadling
> "Standing on the shoulders of some very clever giants!"
> EE : http://www.experts-exchange.com/M_248814.html
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> ZOPA : http://uk.zopa.com/member/RQuadling
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] Very old question: Mysql and old authentication

2009-10-30 Thread Niel Archer
> Recently we update our Local Server to this:
> 
> Apache Version : 2.2.11   
> PHP Version : 5.3.0   
> MySQL Version : 5.1.36   
> 
> All works fine locally, but when we want to connect to a Remote Mysql Server 
> 5.0.45 just can't, we got the "mysqlnd cannot connect to MySQL 4.1+ using old 
> authentication" msg
> 
> The solution as i see is to use the OLD_PASSWORD trick, but in this case we 
> can't do that because the Server is a Shared server and yada yada yada.. 
> change some in the Remote Mysql Server is not an option
> 
> I think Php must provide a solution for this but we can't found it
> 
> We use SqlYog 6.05 to connect to Mysql Server's. Why it works with NEW and 
> OLD algorithm and Php don't ?
> 
> Any help on this please ?

The is an entry concerning this in 5.3.0 Backward Incompatible Changes
http://php.net/manual/en/migration53.incompatible.php

   The new mysqlnd library necessitates the use of MySQL 4.1's newer
  41-byte password format. Continued use of the old 16-byte passwords
   will cause mysql_connect() and similar functions to emit the error,
   "mysqlnd cannot connect to MySQL 4.1+ using old authentication."


The account you are trying to connect with is using an old password hash

Your options are limited, either
1) Compile PHP to use the libmysql library instead of mysqlnd
2) Have the password updated to use the newer hash.

Note The second option will prevent older clients connecting, including
the mysql extension (but not mysqli) if it is not using the mysqlnd
driver.


More information can be found in the MySQL manual on upgrading from v4.0
to v4.1
http://dev.mysql.com/doc/refman/4.1/en/upgrading-from-previous-series.html
http://dev.mysql.com/doc/refman/4.1/en/old-client.html

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] scheduler

2009-09-23 Thread Niel Archer
> Hi,
> 
> I am developing a web application in PHP, the db is mysql.
> 
> I want to develop something like a batch file, which would run everyday,
> query mysql and throw the output to another table which would then perform
> some additional functions.
> 
> Is something like this possible?? i am working on windows thats why said a
> batch,but not rigid about the batch, it cud even be Java.

Not only possible but very simple. Just write the php as normal and use
Windows' Scheduler to run it with something like:

C:\php\php.exe C:\path\to\script.php

I have several scripts like this scheduled to do basic maintenance work
or carry out automated tasks.

> Thanks,
> Vinay

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] losing MySQL resource

2009-09-19 Thread Niel Archer
> I'm maintaining a session.  I successfully connect to a database ($DBConnect
> = mysql_connect()).  I save the connection resource in a session variable
> ($_SESSION['connection'] = $DBConnect) ... to use in subsequent queries.  It
> remains valid while the user is on the current page.
> print_r($_SESSION['connection']) yields 'Resource id #3', for instance.
> 
> User browses to a new page ... in the same session.  $_SESSION['$DBConnect']
> no longer references a valid mysql resource.
> print_r($_SESSION['connection']) yields '0'.
> 
> Other "ordinary" values saved in $_SESSION variables remain valid.
> 
> Is there something special about a mysql resource?

Not about the resource itself, no. PHP closes connections to a Db when a
script ends, unless the connection is persistent, so while the resource
IS saved, the connection to which it refers no longer exists.

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

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] Invalid library (maybe not a PHP library) : Error while loading pdo-ext.

2009-08-31 Thread Niel Archer
Hi

you would do better to raise these issues on the internals lists, either
intern...@lists.php.net or internals-...@lists.php.net

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] newbie: how to return one iteration *per unique date (DAY!)* in a timestamp column?

2009-08-04 Thread Niel Archer
> > I should have given an example ..
> >
> > select count(*) as record_count, date(column_name) as date_field,  
> > 'my_table' as table_name
> > union all
> > select count(*) as record_count, date(column_name) as date_field,  
> > 'my_table_2' as table_name
> >
> > and end up with:
> > count | date   | table_name
> > ---
> > 5 | 2009-01-01 | table 1
> > 10| 2009-01-01 | table 2
> 
> Ben, Chris,
> 
> This is as far as I could get so far:
> 
> $query = "SELECT COUNT(*) AS landing_count, date(solarLandingDateTime)  
> AS solarLandingDate, 't7solar_landingALIAS' AS t7solar_landing UNION  
> ALL SELECT count(*) AS confirm_count, date(solarAweberConfDateTime) AS  
> solarAweberConfDate, 'aweber_7solar_confirmALIAS' AS  
> aweber_7solar_confirm UNION ALL SELECT count(*) AS thankyou_count,  
> date(solarAWDateTime) AS solarAWDate, 'aweber_7solar_awALIAS' AS  
> aweber_7solar_aw";
> 
> $foundUniqueDateROWS = mysql_query($query) or die("query failed:  
> " .mysql_error());
> 
> 
> giving this error:
> query failed: Unknown column 'solarLandingDateTime' in 'field list'
> 
> but I most certainly do have a column named 'solarLandingDateTime' in  
> the table named 't7solar_landing'.
> So I am not sure what it's unhappy.

Yes you do have the column, but your first part doesn't tell the query
which table to use.

UNION is used to join the result of queries together. Each of those
queries must be correctly formed.  The first part of your SQL (before
the first UNION) does not contain a FROM clause, so MySQL tells you
there is no column called 'solarLandingDateTime' because you have no
table.  This same problem applies to each part of your unions.

> 
> John Butler (Govinda)
> govinda.webdnat...@gmail.com
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] newbie: how to return one iteration *per unique date (DAY!)* in a timestamp column?

2009-08-02 Thread Niel Archer
> The distinct can only work as you want it to work when you only select the
> date column and only the date part (not the time part).
> Unfortunately I'm more an oracle DBA where the date functions are more clear
> to me so can not help with exact syntax.
> 
> I think what you should be doing is returning the entire set of records (all
> required columns) in sorted by date order and loop through all of them. keep
> track of the last date processed and if it is the same as the current
> record, process nothing and go get the next record.
> 
> 
> BUT  I am not quite sure what you are trying to achieve so my advise may
> be completely flawed.
> 
> Jack
> 2009/8/3 Govinda 

Doh, should have realised this before, but it's after  4 AM here.

Jack is absolutely correct here, you are getting all the rows back
because that is what the query asks for.  Try this as your first step

SELECT DISTINCT DATE(solarLandingDateTime) AS solarLandingDate
FROM " . $whichTable .  " ORDER BY solarLandingDateTime DESC
LIMIT $Maxrecs2Show") or die("query failed: " . mysql_error());

This should get your unique rows by date. The previous queries used ALL
of the column names to form a unique row, and that made all the rows
DISTINCT.

Give us an idea of your table structure, if possible post the CREATE
statement for it. 


> >  Oops, forgot to mention that with the alias you can change the ORDER BY
> >> clause to use the aliased column data:
> >> ORDER BY solarLandingDate DESC
> >> this will only use the returned data instead of the entire column.
> >>
> >> If you are aliasing a column it is better to use the optional AS keyword
> >>> to avoid confusion.
> >>> MySQL's DATE function returns dates formatted as '-MM-DD' so
> >>> DATE_FORMAT
> >>> is not needed here.
> >>>
> >>
> > Niel, Bastien,
> >
> > thanks for your efforts to lead me to understanding this!
> >
> > I tried everything you both suggested.
> > Ideally I would have some clear docs that outline the syntax for me, for
> > such an example as I need..  and I would be able to check my code myself.
> > Meanwhile, In every case, I just get every record in the table back as a
> > result.
> >
> > So then I thought, "try and make even a *simple* DISTINCT work, and then
> > move on to the date thing"... so I try this:
> >
> > //$foundTrackingRows=mysql_query("SELECT DISTINCT solarLandingDir,
> > solarLandingIP, solarLandingDir, solarLandingDateTime FROM ".$whichTable."
> > ORDER BY solarLandingDateTime DESC LIMIT $Maxrecs2Show") or die("query
> > failed: " .mysql_error());
> >
> > In all the records in this table, there are only 3 possible values in the
> > 'solarLandingDir' column (TINYTEXT):
> > diysolar
> > solar_hm
> > (null)
> >
> > but I still get all the records back, with each distinct 'solarLandingDir'
> > column value represented several times.
> >
> > So something really basic is missing in my understanding/code.
> > Can you see what it is?
> >
> > -Govinda
> >
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> 
> -- 
> Jack van Zanen
> 
> -
> This e-mail and any attachments may contain confidential material for the
> sole use of the intended recipient. If you are not the intended recipient,
> please be aware that any disclosure, copying, distribution or use of this
> e-mail or any attachment is prohibited. If you have received this e-mail in
> error, please contact the sender and delete all copies.
> Thank you for your cooperation

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] newbie: how to return one iteration *per unique date (DAY!)* in a timestamp column?

2009-08-02 Thread Niel Archer
> > >
> > > You need to do this on the mysql side, not in php - php can't  
> > > summarize the data before processing it, so you need to use  
> > > something like the date() function in mysql on your timestamp column.
> > >
> > > http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date
> > >
> > > without knowing your original query it's hard to give an example, but:
> > >
> > > select distinct date(timestamp_column) from table;
> > 
> > Thanks Chris,
> > 
> > I am getting closer, but so far it is not iterating only once per  
> > unique 'date part of the datetime expression', it is returning all the  
> > rows in the table, including those with the very same date but  
> > different time in the value of the 'solarLandingDateTime' column.   
> > There is not alot of discussion in the mysql docs that I saw about how  
> > to work with DISTINCT.  I need to grab data out of the 3 columns:  
> > solarLandingIP, solarLandingDir, solarLandingDateTime  (this part of  
> > my SELECT is working).
> > 
> > This is what I have:
> > 
> > $foundTrackingRows=mysql_query("SELECT DISTINCT  
> > DATE(solarLandingDateTime) solarLandingIP, solarLandingDir,  
> > solarLandingDateTime FROM ".$whichTable." ORDER BY  
> > solarLandingDateTime DESC LIMIT $Maxrecs2Show") or die("query failed:  
> > " .mysql_error());
> > 
> > -Govinda
> 
> 
> There is no comma between DATE(solarLandingDateTime) and  solarLandingIP
> which means the DATE column will use the alias 'solarLandingIP'. Is this
> your intention? Or is the  solarLandingIP another column from the table. 
> If the latter, you may want to do something like this:
> 
>  $foundTrackingRows=mysql_query("SELECT DISTINCT
> DATE(solarLandingDateTime) AS solarLandingDate,
> solarLandingIP, solarLandingDir, solarLandingDateTime
> FROM ".$whichTable.
> " ORDER BY solarLandingDateTime DESC
> LIMIT $Maxrecs2Show") or die("query failed: " . mysql_error());> 

Oops, forgot to mention that with the alias you can change the ORDER BY
clause to use the aliased column data:
ORDER BY solarLandingDate DESC
this will only use the returned data instead of the entire column.

> If you are aliasing a column it is better to use the optional AS keyword
> to avoid confusion.
> MySQL's DATE function returns dates formatted as '-MM-DD' so DATE_FORMAT
> is not needed here.

> --
> Niel Archer
> niel.archer (at) blueyonder.co.uk
> 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] newbie: how to return one iteration *per unique date (DAY!)* in a timestamp column?

2009-08-02 Thread Niel Archer
> >
> > You need to do this on the mysql side, not in php - php can't  
> > summarize the data before processing it, so you need to use  
> > something like the date() function in mysql on your timestamp column.
> >
> > http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date
> >
> > without knowing your original query it's hard to give an example, but:
> >
> > select distinct date(timestamp_column) from table;
> 
> Thanks Chris,
> 
> I am getting closer, but so far it is not iterating only once per  
> unique 'date part of the datetime expression', it is returning all the  
> rows in the table, including those with the very same date but  
> different time in the value of the 'solarLandingDateTime' column.   
> There is not alot of discussion in the mysql docs that I saw about how  
> to work with DISTINCT.  I need to grab data out of the 3 columns:  
> solarLandingIP, solarLandingDir, solarLandingDateTime  (this part of  
> my SELECT is working).
> 
> This is what I have:
> 
> $foundTrackingRows=mysql_query("SELECT DISTINCT  
> DATE(solarLandingDateTime) solarLandingIP, solarLandingDir,  
> solarLandingDateTime FROM ".$whichTable." ORDER BY  
> solarLandingDateTime DESC LIMIT $Maxrecs2Show") or die("query failed:  
> " .mysql_error());
> 
> -Govinda


There is no comma between DATE(solarLandingDateTime) and  solarLandingIP
which means the DATE column will use the alias 'solarLandingIP'. Is this
your intention? Or is the  solarLandingIP another column from the table. 
If the latter, you may want to do something like this:

 $foundTrackingRows=mysql_query("SELECT DISTINCT
DATE(solarLandingDateTime) AS solarLandingDate,
solarLandingIP, solarLandingDir, solarLandingDateTime
FROM ".$whichTable.
" ORDER BY solarLandingDateTime DESC
LIMIT $Maxrecs2Show") or die("query failed: " . mysql_error());> 

If you are aliasing a column it is better to use the optional AS keyword
to avoid confusion.
MySQL's DATE function returns dates formatted as '-MM-DD' so DATE_FORMAT
is not needed here.

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] Single Quotes in Form Inputs

2009-07-27 Thread Niel Archer
> I prefer PHP Data Objects http://in3.php.net/manual/en/book.pdo.php to
> addslashes and mysql_real_escape_string

I prefer PDO myself.  However, it is not necessarily safer.  When using
prepared statements the parameters are automatically escaped similar to
mysql(i)_real_escape_string, if my reading of the documentation is
correct. But as far as I can tell no escaping is performed on PDO::query
or PDO::exec other than what you do yourself, so you have the same risks
that need to be addressed.
> 

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] Single Quotes in Form Inputs

2009-07-27 Thread Niel Archer
> Hi,
> 
>  
> 
> I have a form in which my sales reps can add new clients into the database,
> but I'm running into a problem if the client's name includes a single quote,
> such as O'Henry, when it comes time to input the form data into the database
> table.  I'm guessing I need to use ereg_replace, or something similar, to
> change the single quote, but I still can't seem to get the syntax right.
> Any help would be appreciated.  For what it's worth, here is a shortened
> version of what I have:

You shouldn't be trusting form data.  Single quotes can also be used to
add SQL injection.

Replace these two lines:

> $ firstName = "$_POST[form_firstName]";
> $ lastname = "$_POST[form_lastName]";

with:

$ firstName = mysql_real_escape_string($_POST['form_firstName'], $conn);
$ lastname = mysql_real_escape_string($_POST['form_lastName'], $conn);

Where $conn is your connection resource. Note also I've quoted the key
names, as they should be unless they are valid constants.
 This will escape any newlines, apostrophes (single quotes), etc. and is
the absolute minimum you should be doing with any data you do not supply
yourself

> $query = mysql_query("INSERT INTO customers (`cust_first`,`cust_last`)
> VALUES ('$firstName','$lastName')");
> 
>  
> 
> Ben Miller

BTW ereg functions are deprecated in PHP 5.3, so now would be a good
time to start using the PCRE equivalents.


--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] simple INSERT statement with placeholders failing. I don't understand why.

2009-07-13 Thread Niel Archer
> this:
> 
> $q=mysqli_query($db_billing,'INSERT INTO billing (clientFname,  
> clientLname) VALUES (?,?)', array($defaultsFormVars[clientFname],  
> $defaultsFormVars[clientLname]));
> 
> is giving
> Warning: mysqli::query() expects parameter 2 to be long, array given  
> in /home/meee/public_html/somedir/test.php on line 71
> 
> a "long"?!  We need values for 2 text/BLOB columns..  an array seems  
> appropriate to me.  It was with PEAR DB.   WHy is it asking for a long?
> 
> it was working fine with PEAR DB before I turned that off to try and  
> learn better what was under PEAR.
> I found
> http://dev.mysql.com/doc/refman/5.1/en/insert.html
> but there is no example of using placeholders there, so I can't  
> determine how to alter this example (which I learned from a book that  
> just breezes through with only the one quick PEAR DB example.)
> 
> If someone can even just point me to the right docs for this, I'd be  
> grateful.
> thanks!

http://uk.php.net/manual/en/mysqli.query.php

(Almost) all php functions are documented on the web site. So it would
be the best place to start looking.


You are mixing up several different methodologies in the example you
show.

More generally for MySQLi start here:

http://uk.php.net/manual/en/book.mysqli.php

It has links to the appropriate function references for the MySQL
Improved interface.

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

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] mysql_insert_id() and JOIN

2009-07-12 Thread Niel Archer
> Sorry my question... but why I must use JOIN if I can use SELECT * FROM
> table1 AND table2 AND table3 WHERE table1.id=table2.id=table3 not?
> thanks

You can not use that syntax on MySQL (at least  not on v5.0 or v5.1, I
do not know about earlier versions).


>// Emiliano Boragina _
>// Diseño & Comunicación //

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] Re: [PHP] A prepared statements question

2009-07-12 Thread Niel Archer
> 
> [Redirected to PHP-DB: php...@lists.php.net]
> 
> 
> On Sun, Jul 12, 2009 at 00:31, Jason Carson wrote:
> > Hello everyone,
> >
> > I am having a problem getting my prepared statements working. Here is my
> > setup...
> >
> >    index.php -> authenticate.php -> admin.php
> >
> > 1)index.php has a login form on it so when someone enters their username
> > the form redirects to another page I call authenticate.php.
> >
> > 2)In the authenticate.php file I want to use prepared statements to
> > interact with the MySQL database. I want to compare the username submitted
> > from the form with the username in the database.
> >
> > 3)If the login username was legitimate then you are forwarded to admin.php
> >
> > Its step 2 I am having problems with. Here is what I have but I don't
> > think it makes any sense and it doesn't work.
> >
> >
> > $link = mysqli_connect($hostname, $dbusername, $password, $database);
> > $stmt = mysqli_prepare($link, "SELECT * FROM administrators WHERE
> > adminusers=?");
> > mysqli_stmt_bind_param($stmt, 's', $username);
> > $result = mysqli_stmt_execute($stmt);
> >
> > $count=mysqli_num_rows($result);
> >
> > if($count==1){
> > header("location:admin.php");
> > } else {
> > echo "Failure";
> > }
> >
> > Any help is appreciated.

The main problem is you are not testing your results.  With that code
you do not even know if you have a connection or not.  I'd say there is
a good chance you do not have error reporting enabled or you would have
picked up the error straight away.

mysqli_stmt_execute returns a boolean indicating success or failure. 
You are trying to use it as a result set, which will not work.  Replace:

$count=mysqli_num_rows($result);

with:

mysqli_stmt_store_result($stmt);
$count = mysqli_stmt_num_rows($stmt);

> 
> -- 
> 
> daniel.br...@parasane.net || danbr...@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 Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--
Niel Archer



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



Re: [PHP-DB] mysql_insert_id() and JOIN

2009-07-11 Thread Niel Archer
> Hi again…
> 
> I dont understand how to use this two…
> 
> I read php.net and other sites, but dont understand...

http://dev.mysql.com/doc/
Available in the major languages, pick your filter and start reading.
Having documentation in your own language may help a lot towards
understanding.

> I have this four tables: table1, 2, 3 and 4
> 
> So the SELECT is like this?:
> 
>  
> $query_select = "SELECT * FROM table1 FULL JOIN table2 FULL JOIN table3 FULL
> JOIN table4 ON table1.id=table2.id=table3.id=table4.id ORDER BY id ASC”;
> 
> mysql_query($query_select);
> 
> ?>
> 
> This is with FULL JOIN... How identificate the left table if I want to use
> LEFT JOIN?

The left table is the table to the left of the join. So:

SELECT id FROM table1 LEFT JOIN table2...

table1 is the left table and table2 is the right table (if you were to
use a RIGHT JOIN).

> 
> How is the UPDATE?
> 
> And the INSERT I dont understand yet how is it?

UPDATEs and INSERTs follow the same procedure.

When you INSERT an entry into the main table, you then use the function
mysql_insert_id() which will give you the value of the last 'id' column
generated, which you can then use to insert data into the secondary
tables.

> 
> I’m not to do a link between tables in PHPMyAdmin?
> 
>  
> 
> Thank you very... VERY... much!
> 

If you are using MySQL 4.1 or later you should use the mysqli extension
and not the older mysql one. UNLESS you are relying on the older style
passwords, which is a BAD idea.

--
Niel Archer



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



Re: [PHP-DB] mysqli error

2009-07-01 Thread Niel Archer
> Whenever I run the following code, I get the error: "Commands out of sync;
> you can't run this command now" as I try to execute my prepared Update
> statement.
> 
>  $fpiDataAddr = fopen('outputAddr.txt','r') or die("can not open In File ");
> 
> //Connect to mySQL server
> $mysqli = new mysqli('localhost', 'user', 'pswd', 'db');
> if ($mysqli->connect_error) { die('Could not connect:
> '.$mysqli->connect_error); }
> else{ echo "Connected successfully\n"; }
> 
> $seqno = 0;
> $k = 'Kev';
> 
> $sql1 = 'SELECT UNIQUE_NUM, AM_CITY FROM db.kb_addr WHERE UNIQUE_NUM = ?';
> $sth1 = $mysqli->prepare($sql1);
> 
> $sql2 = 'UPDATE db.kb_addr SET AM_CITY = ? WHERE UNIQUE_NUM = ?';
> $sth2 = $mysqli->prepare($sql2);
> 
> while($inrec = fgetcsv($fpiDataAddr,0,',','"')){
> 
> if($seqno == 0){
> $x= count($inrec);
> $arrFields = array();
> for ($y = 0; $y < $x; $y++) {
> $arrFields[$inrec[$y]] = $y; //creates associative array that
> associates fields with the index in $inrec
> }
> 
> echo "Array of Field Names From Header Record in Input data is \n";
> print_r($arrFields);
> $seqno++;
> continue;}
> 
> $key = 0+$inrec[$arrFields['Unique #']];
> 
> //Select Statement
> $sth1->bind_param('i',$key);
> $sth1->execute();
> $sth1->bind_result($un,$ac);
> $sth1->fetch();
> 
> //Update Statement
> $sth2->bind_param('si',$k,$key);
> echo "after bind: ".$sth2->error."\nThe object error is:
> $mysqli->error\n";
> $sth2->execute();
> echo "after execute:  ".$sth2->error."\nThe object error is:
> $mysqli->error\n";
> 
> if($seqno > 1000) break;
> $seqno++;
> }
> 
> fclose($fpiDataAddr) or die("can not close file");
> 
> //disconnect
> $sth1->close();
> $sth2->close();
> $mysqli->close();
> ?>
> 
> 
> 
> However, if I close $sth1 (the select statement) before executing $sth2 (the
> update statement), it works, but since I just closed $sth1, I have to
> prepare it again. This is pretty inefficient considering the large data set
> that I'm working with and the fact that I have to prepare and close my
> select statement every single time I loop through. Is there any way that I
> can run these statements error-free without having to close the select
> statement ($sth1) every single time I want to execute my update statement
> ($sth2)?

You do not initialise your statement object.  I would guess this is a
large part of the problem, although I'm not that familiar with prepared
statements in MySQLi.

 See the documentation for mysqli::stmt_init[1]  and the example for
mysqli_stmt::prepare[2] in the php documentation.

[1] http://docs.php.net/manual/en/mysqli.stmt-init.php
[2] http://docs.php.net/manual/en/mysqli-stmt.prepare.php


> Thanks,
>   Kevin

--
Niel Archer
niel.archer (at) blueyonder.co.uk



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



Re: [PHP-DB] Not Valid URL

2009-02-23 Thread Niel Archer
> Hi,
> 
> I stuck with something like this. I have two file test.html with  only 
> 'aaa' and main.php with
> '
> echo file_get_contents('test.html').'';
> echo 'aaa';
> 
> ?>'
> The problem is tak this two links are different.
> First is http://localhost/game/php/%5C%22../index.php%5C%22
> Second is http://localhost/game/index.php
> 
> Paste from FireFox:
> aaa <http://localhost/game/php/%5C%22../index.php%5C%22>
> aaa <http://localhost/game/index.php>
> 
> I copy file to remote serwer at work and school and both are the same. 
> Problem is somewhere in my computer. I think in my php configuration, 
> but I don't know where to look.
> Would appreciate it greatly if anyone can help.
> 
> Regards,
> Kamil Walas

Check the file containing the first link again.   '%5c%22' is the
characters '\"'.  Seems you have escaped the double quotes in a single
quoted string


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

--
Niel Archer



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



Re: [PHP-DB] Bulk Insert from text file

2008-09-25 Thread Niel Archer
Hi

>   Could any 1 please help on how to insert using phpMyAdmin??

I haven't used phpMyAdmin in years, but here's how I'd do it in SQL with
my favourite tool (SQLyog)

LOAD DATA LOCAL INFILE 'C:\file_name.txt'
 INTO TABLE tbl_name
  FIELDS TERMINATED BY '\t'
  LINES TERMINATED BY '\n'
 IGNORE 1 LINES
 (col_name1, col_name2, col_name3);

Some things to note.
1) the LOCAL keyword is for a file on YOUR computer.  Remove it if the
file is located on the server.  Many shared hosting packages do not
allow you to use LOCAL.

2) IGNORE 1 LINES assumes your file has column names or similar in the
first line, and ignores them. Remove if the file does not have any, or
increase the number if more than one non-data line at the start.

3) The two TERMINATED clauses define the line as being newline
terminated and fields separated by tabs.  Change these accordingly.  You
may need to add an extra backslash  to escape the backslash for
phpMyAdmin, I do not remember how that works with phpMyAdmin.

--
Niel Archer



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



Re: [PHP-DB] solution reqd for summation of vertical columns in PHP

2008-09-14 Thread Niel Archer
> 
> On Sep 13, 2008, at 10:05 PM, Vaibhav Informatics wrote:
> 
> > Please let me know if there is a simple method to total up the  
> > column values
> > in Mysql database tables using php as in excel.
> 
> I believe what you are looking for is count(fieldname)

COUNT returns the number of rows.  I think they're after SUM

SELECT SUM(price) WHERE available = 1;

would total the values in the returned row's price column

--
Niel Archer



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



Re: [PHP-DB] If( Query)

2008-09-07 Thread Niel Archer
Hi

> I have the following function:
> 
> function 
> add_item($item_name,$item_desc,$item_price,$item_man_id,$item_cat_id,$item_pix)
> {
> connect();
> if($item_pix == "")
> {
> $sql = "INSERT INTO items 
> (item_name,item_desc,item_price,item_man_id,item_cat_id) VALUES 
> ('$item_name','$item_desc','$item_price','$item_man_id','$item_cat_id')";
> }
> else {
> $sql = "INSERT INTO items 
> (item_name,item_desc,item_price,item_pix,item_man_id,item_cat_id) VALUES 
> ('$item_name','$item_desc','$item_price','$item_pix','$item_man_id','$item_cat_id')";
> }
> mysql_query($sql);
> return;
> }
> 
> I am using the if statement because i want it so that if no picture is 
> uploaded the entry is blank and the mysql database has a default entry 
> of na.gif which is a "picture coming soon picture".
> 
> It works fine when i run in localy on MAMP, but if i run it on my web 
> server it doesnt add the row.

You should be checking the mysql_query call for success and output the
error if it fails.  Something like:

   mysql_query($sql) or die('Insert failed: ' . mysql_error());

You'll now why it's failing then.  Make sure you have error reporting
enabled.

> Is this a compatability error? or is there a better way to write this?
> 


--
Niel Archer



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



Re: [PHP-DB] Help to improve MySQL query

2008-08-08 Thread Niel Archer
 Hi

You do not say how you identify the last call (there is no date/time
field for example), so a complete answer is not really possible

Do not use "NOT LIKE 'Completed'", it's an inefficient way of doing "!=
'Completed'"
--
Niel Archer



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



Re: [PHP-DB] Select...

2008-01-15 Thread Niel Archer
Hi

First off, please create your own thread, do not reply to someone else's
and change the subject.

> I'm having kind of trouble to get done this: Select data from a table,
> except those data already in a second table. Actually,  if there is a rowid
> in table2, I wont get it from table1, rowid is the key that relates both
> tables.
> 
> I just can't express this with a SQL statement!! idequipomed is the key that
> relates both tables!!
> So, if idequipomed is already in Table2, I shouldn't get it from Table1.
> Any suggestions?

You need to do a join between the two tables using the common column to
make the connection. This  should get you started

SELECT * FROM Table1 RIGHT JOIN Table2 USING (idequipomed) WHERE 
Table1.idequipomed
IS NULL


--
Niel Archer

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



Re: [PHP-DB] php maximum characters in text field

2007-10-17 Thread Niel Archer
Hi

> Does anyone know how to look for a "Curly quote" or "typographer's quotation 
> mark".

Do you mean the equivalent of the left and right double quote entities
in HTML (or 66's and 99's as we called them at school)?


--
Niel Archer

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



Re: [PHP-DB] Variables & Forms

2007-10-17 Thread Niel Archer
Hi Ron

"" is perfectly legitimate in an e-mail header field like "Subject:".
All headers may contain any combination of ASCII characters except CR
and LF which are used to terminate the field (See RFC8222 section 2.2).

There is also defined a means to "fold" lines which involves using the
CR+LF+white-space combination to indicate multiple line entries.  Is it
possible your e-mail header fields are doing this and your access to the
headers does not take this possibility into account?  Without your POP
handling code it's impossible to say whether this is your problem or not.

--
Niel Archer

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



Re: [PHP-DB] Inserting databasecontent within the same form

2007-09-27 Thread Niel Archer
Hi Ruprecht,

> > SELECT Kunden.*, City.name, City.vorwahl FROM Kunden LEFT JOIN City
> > USING (zipcode)
> 
> I'm understanding you this is a way for designing the sql-statement.

Yes.

> My customer want that they have inserted the city after typing in the
> zipcode in the zipfield. The city should be searched in a database and
> inserted in the field city automaticly.

> I think the only way is to do that with some ajax-code combined with a
> short phpscript.
> 
> Actually I have these codes, but the automatic inserting fails, I don't
> know why.



Dynamically changing the fields, I'm afraid I can't help. You would be
better trying a list dedicated to ajax.


--
Niel Archer

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



Re: [PHP-DB] Inserting databasecontent within the same form

2007-09-26 Thread Niel Archer
> How can I overtake the fieldvalues of city and the first part of the
> phonenumber. It should read out the value of the zipfield and check them
> with the content of the table "ort". If there is found a recordset with
> the same plz the formfields city and the the field "vorwahl" should get
> the values of the fields of the recordset.

I'm having troubling understanding exactly what you want  and I don't
have time to decipher all the code in the hope it will tell me.  My best
guess is you want to use the zipcode from one table, to automatically
add the city name into a form from another table.  If that is so, you
can do it with your query using a join.

SELECT Kunden.*, City.name, City.vorwahl FROM Kunden LEFT JOIN City
USING (zipcode)

This assumes that `zipcode` exists in both tables and is unique in the
"City" table.  You should also process the City.name and City.vorwahl
results for NULL results where `zipcode` does not exist in the "City"
table.

--
Niel Archer

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



Re: [PHP-DB] Data not fetching in the textfield.

2007-09-26 Thread Niel Archer
Your variable value is not being inserted because you have used single
quotes for the echo, not double quotes as the nabble example does. 
Special characters and variables are only interpreted in double quotes,
they are treated literally in single quotes.

--
Niel Archer

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



Re: [PHP-DB] Pages not fully loading

2007-09-24 Thread Niel Archer
> Further testing shows that the script fails just before the mail() line, 
> though after a variable number of refreshes it goes through and 
> downloads all OK.  Can anyone think why there should be this occasional 
> interaction between the mail() command line and the php script.

Without seeing the code, No!

--
Niel Archer

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



Re: [PHP-DB] Query syntax

2007-09-15 Thread Niel Archer
If I understood you correctly (and I'm not sure I did), this should do
it

$query="SELECT * FROM table WHERE listing_type LIKE '%$listing_type%' 
AND  listing_approved IN( '1' ,'2') ORDER BY name ASC";

--
Niel Archer

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



Re: [PHP-DB] showing warnings

2007-09-11 Thread Niel Archer
> > This shows you have NO indexes on the table.  Assuming that 'Tune_Name'
> > contains unique entries for each row, I'd suggest you do the following
> > as a minimum:
> >
> > ALTER TABLE Mobile_Tunes ADD PRIMARY KEY (Tune_Name);
> 
> How's that going to help if he's getting all records from the table?

 Depends what you mean by help.
 Improve performance of the query, not at all, but that wasn't the
original question.  
In a previous post he said he'd added indexes which his EXPLAIN output
clearly shows is not the case.  That is simply an example of how to add
a PRIMARY KEY after creating the table.  However, it will stop duplicate
entries from being entered and prepare the way for when he's NOT
selecting all rows, so is not entirely wasted.

> Also there's no way a database is going to use an index if there are
> only 4 rows in the table.

True, but if it was only ever going to have 4 entries in it I doubt he'd
be using a Db at all.  I'm assuming this is just a sample.

--
Niel Archer

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



Re: [PHP-DB] showing warnings

2007-09-11 Thread Niel Archer
>   
> mysql> explain SELECT Tune_Name,Tune_Type FROM Mobile_Tunes;
> +--+--+---+--+-+--+--+---+
> | table| type | possible_keys | key  | key_len | ref  | rows |
>  Extra |
> +--+--+---+--+-+--+--+---+
> | Mobile_Tunes | ALL  | NULL  | NULL |NULL | NULL |4 |
>|
> +--+--+---+--+-+--+--+---+
> 1 row in set (0.00 sec)
>   mysql>

This shows you have NO indexes on the table.  Assuming that 'Tune_Name'
contains unique entries for each row, I'd suggest you do the following
as a minimum:

ALTER TABLE Mobile_Tunes ADD PRIMARY KEY (Tune_Name);


--
Niel Archer

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



Re: [PHP-DB] __CYGWIN32__

2007-08-06 Thread Niel Archer
Hi

  This is the wrong place to be asking really.  This list is for using
PHP with databases, not installing PHP even if it's with a database.

  While I'm far from being a Linux Guru, I can't think of any reason
that you should get any references to CygWin, which is a Windows package
to allow a Unix-Like environment.

  You need a list like the developers one, where they're more
knowledgeable with building PHP/MySQL


--
Niel Archer

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



Re: [PHP-DB] Store more than 1 piece of information in a single variable

2007-08-03 Thread Niel
> First.. You're using mysql_fetch_array when you wanted
> mysql_fetch_assoc.. .. select user_id from whatever .. and then $row =
> mysql_fetch_array($res) .. youd have a $row[0].. mysql_fetch_assoc
> would allow $row['user_id']

 mysql_fetch_array($res) will fetch both associative and numerical
indexes, so it will have  $row[0] and $row['user_id'] in it. It has an
optional second parameter to indicate associative, numerical or both,
defaulting to both.  mysql_fetch_row only fetches numerically indexed
arrays

--
Niel Archer

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



Re: [PHP-DB] mysql different server different EXPLAIN result

2007-07-24 Thread Niel
Hi

> I'm running 3 servers with mysql database
> - Local : 5.0.18-log, MySQL Community Edition (GPL)
> - Main Server : 4.1.22-standard-log, MySQL Community Edition - Standard 
> (GPL)
> - Backup Server : 4.1.20, Source Distribution
> 
> I copied a database from the Main Server to Local and Backup Server and 
> run a SQL
> explain command on the database but i get different EXPLAIN result. I 
> think because
> i copied it from one source shouldn't it show the same EXPLAIN result 
> cause i didn't
> change any of the index, keys or records

Not if that's what has changed between versions. Check the change log
for details of what was altered, to see if it's relevant.

--
Niel Archer

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



Re: [PHP-DB] PHP + PostgreSQL: invalid byte sequence for encoding "UTF8"

2007-07-21 Thread Niel
Hi

You still haven't answered whether you're using any output handler, and
if so which one.  I use

   output_handler=mb_output_handler

> I overloaded the mbstring variables with:
> mbstring.func_overload = 6
> Setting it to "7" won't let me even echo something else.

Very strange, the only additional function overloaded is mail() and that
shouldn't stop you using echo.

As well as setting the internal encoding and enabling it with
mbstring.encoding_translation = On
   mbstring.internal_encoding = UTF-8

I would also use:
mbstring.language = English 
; or German in your case
mbstring.detect_order = UTF-8,eucjp-win,sjis-win
mbstring.http_input = UTF-8,SJIS,EUC-JP
mbstring.http_output = UTF-8

> Is it possible for mbstring to overload the pg-functions I need?
 No, and it shouldn't be needed. Those functions should be UTF-8 enabled
in order to communicate with the database and supply the correct data

  You're still referring to 'UTF8' which as I pointed out isn't the
official name of the encoding system.  I have no idea if PHP will
recognise  it, but to be safe I suggest you use the official 'UTF-8'
(hyphen between letters and number) in case it's causing problems.
  The other thing to be wary of, is output to the console. Some OSes do
not support unicode in the console.  So unless you're certain yours does,
I wouldn't use it as a test.

--
Niel Archer

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



Re: [PHP-DB] PHP + PostgreSQL: invalid byte sequence for encoding "UTF8"

2007-07-21 Thread Niel
Hi

> 
> Well, I searched all the source code of phpPgAdmin for charsets and I found:
> 
> "echo "\t charset={$data->codemap[$dbEncoding]}\" />\r\n";"
> 
> So this means, phpPgAdmin sets the output charset to the charset which
> is used by the databased connected to - but that's still not the
> problem, because I also know how to fix charset output in browsers.

Not exactly. As far as I can see, it only changes the value of the 
Content-type: header
in the HTML, it doesn't change the actual encoding output.

> > Once again indicating your data needs to be converted from some other
> > character set.
> 
> It's already converted to be compatible to utf8 when fetching it from some 
> other ressources.

I didn't mean the content of the database,. I was referring to the data
that PHP is actually processing, which appears to have been converted
within PHP

> Well, I've set the default_charset to UTF8, it was set before to "" (empty) -
> but the output on console (cli) and the problem is still the same also
> after changing this to UTF8, so: this is not the problem, 
.
It should be "UTF-8", this is the official designation from unicode,
although case will likely be ignored. As far as I know "UTF8" is not a
recognised encoding
  This however, is only the value that will be output as the
Content-Type charset, as noted above.


> I fetch something from database, which looks like "lacarrière" when I output 
> it in
> PHP - well don't let us get confused from PHPs output. Then I fetch
> something from another ressource looking like "lacarrière" - when I
> compare both strings in PHP it tells me that they are "not equal".

As I said before. Many of PHP's functions (the string one's for
comparing for example) are NOT multi-byte aware, so are NOT guaranteed
to work correctly.

You did not answer the most important question. What, if any, output
buffering are you using?  Are you using the mbstring module?  If so, is
it set to overload the old string functions?

--
Niel Archer

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



Re: [PHP-DB] PHP + PostgreSQL: invalid byte sequence for encoding "UTF8"

2007-07-21 Thread Niel
Hi

Please configure your email client so we don't receive 5 copies of your
mail.

> I already did this and all encoding settings are right, but I figured out 
> something more.
> 
> 1) Using pg_query for fetching UTF8 data from database is working properly. 
> Of course when I try to output it direclty then I get something like that as 
> output "lacarrière" - but when I use utf8_decode() on the UTF8-bytes I get 
> it the right way "lacarrière".

This indicates that PHP not using UTF-8.  That output is typical of
UTF-8 output as Latin characters.

> 2) I found another PHP application which is able to insert UTF8 data 
> properly, phpPgAdmin, but it seems that it uses the ADODB-Layers for 
> executing SQL-statements.
> Well, the fact that phpPgAdmin runs on the same machine handling properly 
> UTF8 data means that my PHP is well configurated handling UTF8.

Not true, it only indicates that phpPgAdmin is is configured to handle
UTF-8 correctly.

> 3) When I add to my DB-Class utf8_encode() on the querystring I send to the 
> database, it works properly, the insert is fine, so that's a temporary 
> solution for my first problem.

> 4) When I get data from database I usually would have to do a utf8_decode on 
> EVERY string which is fetched from database. So my solution is now, to handle 
> all strings comming UTF8 from database as they are comming with UTF8-bytes, 
> and really only then  when I need to decode them I decode them for further 
> use.

Once again indicating your data needs to be converted from some other
character set.


I had similar problems getting PHP to work with UTF-8 and MySQL.  Many
of PHP's function are not multibyte aware and assume a Latin character set.

What, if any, output buffering are you using? What is your
default_charset set to?

--
Niel Archer

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



Re: [PHP-DB] PHP & MySQL Issue!

2007-07-12 Thread Niel
Hi

Give us a clue? What's the error(s) you get returned?
--
Niel Archer

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



Re: [PHP-DB] PHP/MySQL UTF-8 SNAFU

2007-07-12 Thread Niel
Hi

What functions are you using?  Many of PHP's functions are not multibyte
aware and default to ASCII.  I had this problems myself end of last year.
--
Niel Archer

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



Re: [PHP-DB] Newbie alert: supplied argument is not a valid MySQL result resource

2007-07-11 Thread Niel
Hi

> On my way to bed so too tired too look closely, but at a guess I'd say
> it's a logic error.  I would guess this:
> 
> >$sid = mysql_fetch_array($query) || die ('Could not fetch from database: 
> > ' . mysql_error());   // <---  line 49
> 
>  isn't evaluating in the order you expect.. You're using a logic
> statement as an assignment, and the result of that get's assigned to your
> variable not the resource you expect. Try it like this to see if it works:
> 
> $sid = mysql_fetch_array($query);
> if ($sid === false) die ('Could not fetch from database:  ' . mysql_error()); 
> 
> If that's not the problem, I haven't got a clue until after sleep and
> coffee.

I've had some sleep, and coffee, and I see I missed something silly.

I should of suggested this

 // get sid and write cookies
   $query = mysql_query("SELECT MAX(SID) FROM Sessions");
  if ($query === false)  die ('Could not query database: ' . mysql_error());
   $sid = mysql_fetch_array($query)
  if ($sid === false) die ('Could not fetch from database:  ' . mysql_error()); 


--
Niel Archer

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



Re: [PHP-DB] Newbie alert: supplied argument is not a valid MySQL result resource

2007-07-09 Thread Niel Archer
Hi

On my way to bed so too tired too look closely, but at a guess I'd say
it's a logic error.  I would guess this:

>$sid = mysql_fetch_array($query) || die ('Could not fetch from database: 
> ' . mysql_error());   // <---  line 49

 isn't evaluating in the order you expect.. You're using a logic
statement as an assignment, and the result of that get's assigned to your
variable not the resource you expect. Try it like this to see if it works:

$sid = mysql_fetch_array($query);
if ($sid === false) die ('Could not fetch from database:  ' . mysql_error()); 

If that's not the problem, I haven't got a clue until after sleep and
coffee.

Niel

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



Re: [PHP-DB] Re: record pointer

2007-07-05 Thread Niel Archer
Hi

> mysql> select id,cat from table where cat=(select cat from table where id=51);
> +-+--+
> |  id | cat  |
> +-+--+
> |  40 | FLK  |
> |  41 | FLK  |
> |  42 | FLK  |
> |  44 | FLK  |
> |  45 | FLK  |
> |  46 | FLK  |
> |  47 | FLK  |
> |  48 | FLK  |
> |  49 | FLK  |
> |  50 | FLK  |
> |  51 | FLK  |
> |  52 | FLK  |
> |  53 | FLK  |
> |  54 | FLK  |
> |  55 | FLK  |
> |  56 | FLK  |
> |  57 | FLK  |
> |  58 | FLK  |
> |  59 | FLK  |
> |  60 | FLK  |
> +-+--+
> 20 rows in set (0.02 sec)

> now I can select the whole cat when I enter an ID that is fine! but the query 
> should 
> stop at id=$id or in other words in the end it should POINT to id=$id
> in the above example the last record would be the record with id=51
> do I need another SELECT here?

If I understand that correctly, you only need to add the extra condition
to the WHERE clause of the main query.  So:

SELECT id, name, cat FROM table 
WHERE cat = (SELECT cat FROM table WHERE id = $ID) AND id <= $ID;

This should display all rows, before and including the row with the same
'cat' as 'id' has. For your example of $ID = 51 it should display:

+-+--+
|  id | cat  |
+-+--+
|  40 | FLK  |
|  41 | FLK  |
|  42 | FLK  |
|  44 | FLK  |
|  45 | FLK  |
|  46 | FLK  |
|  47 | FLK  |
|  48 | FLK  |
|  49 | FLK  |
|  50 | FLK  |
|  51 | FLK  |
+-+--+


Niel

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



Re: [PHP-DB] Re: record pointer

2007-07-05 Thread Niel Archer
Hi

>   O.K. the id column is primary key and it is auto_incerment .I think my 
> explanation was not clear enough :
>  
>  this is my query : SELECT * FROM table WHERE ID=$ID
>  this will find the record with the specified ID and I will be able to see 
> it,  now I want to be able to scroll up and down to all the records that 
> belong to the same cat(egory)!

Assuming that is correct now, use a sub-query:

SELECT id, name FROM table 
WHERE cat = (SELECT CAT FROM table WHERE id=$ID);

Niel

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



Re: [PHP-DB] Catchable fatal error: Object of class stdClass could not be converted to string in on line

2007-06-25 Thread Niel Archer
Hi 
Seeing as no-one else has replied to this, I'll make a comment.  First
off let me state I don't use PDO so I am not familiar with it.

It would appear to me that your "problem" line is NOT the problem. It is
only where the error is reported from.  That line is a call to an object
method, so the problem is in that method. As you haven't supplied the
code for that method, no one is able to help.

> A point of note is that my $dbh is being created in my class constructor
> as a private. The method that is calling the prepare and execute
> statements is a public. I don't thing I'm trying to do anything new or
> exotic, I don't think I'm trying to convert the object to a string, just
> execute the query statement

Probably not relevant, although it likely would be better to assign by
reference.

$prep_users =& $this->dbh->prepare($sql_users);

The main problem is we don't know what your $dbh is. We can guess it's a
database handle, but that really doesn't tell us anything useful, like
how it is constructed, and what the method  you try calling is trying to
do

We need to see the code for the method:

$prep_users->execute();

as that is where the error is occurring, and possibly the constructor and
prepare methods also.


Niel

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



Re: [PHP-DB] how to delete

2007-06-19 Thread Niel Archer
Hi

There is no DESTROYIMAGE() function. May be you mean imagedestroy(). If
so this does NOT erase files, it destroys in memory images created using
the Image functions.

  To erase files use the unlink function. For detail look here 
http://uk3.php.net/unlink

Niel

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



Re: [PHP-DB] Problem with rss-feed generation

2007-06-15 Thread Niel Archer
Hi

> Du you know a good tutorial for XML and RSS, possible relating with PHP.

Not a tutorial, no.  I got my information from the specification
documents.

You should consider changing your method.  Instead of creating the
RSS/XMl file manually, try using one of the PHP extensions that will
generate XML for you, like the PEAR XML_Query2XML package which converts
SQL SELECT results into valid XML data. Or PECL's xmlwriter.


Niel

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



Re: [PHP-DB] Problem with rss-feed generation

2007-06-15 Thread Niel Archer
Hi

> firefox tells me that it dislike the closing xml-tag.
> In my quanta-editor it seems that can be difficulties with the tagend of
> the opening xml-line of the second position of the questionmark.

Because you missed the  space in front of it.

You really need to find out more about XML and RSS specifications.  This
isn't a PHP or Db problem so doesn't belong on this list.

Niel

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



Re: [PHP-DB] Problem with rss-feed generation

2007-06-15 Thread Niel Archer
Hi

> ok by beginning the php-code with  Unfortunately my RSSowl tell me that there must be other errors in the
> xml-formating. And I don't got a detailed information what RSSowl
> dislike in the xml-file.

Try opening it in a browser. Opera, for example, tells you what error it
encounters.  That's how I identified your initial error.

Niel

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



Re: [PHP-DB] Problem with rss-feed generation

2007-06-15 Thread Niel Archer
Hi

the first line is badly formed



Should be:




Niel

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



Re: [PHP-DB] tell me syntax

2007-06-12 Thread Niel Archer

http://dev.mysql.com/doc/refman/5.1/en/grant.html

Niel

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



Re: [PHP-DB] tell mysql error

2007-06-08 Thread Niel Archer
Hi

Sounds like you do not have the required privileges with your user
account..  I suggest you spend some time reading the MySQL documentation
on privileges.

Are you using the root account? Have you created other user accounts and
given them the required privileges?



Niel

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



Re: [PHP-DB] tell mysql error

2007-06-05 Thread Niel Archer
Hi

>   mysql -h localhost -u root -p 123456

 should be:

   mysql -h localhost -u root -p123456

notice no space after -p or it asks for the password.


Niel

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



Re: [PHP-DB] 20K photos

2007-04-29 Thread Niel Archer
Hi

>  Imagine that you want to put some 2 historical photos On display in 
> your website , you use PHP and MySQL.
>   Preparing a photo album with 200 photos is no problem but for 2 photos! 
> would you do it in the same way? 

Yes, but I don't necessarily see the need for a db.

If you have additional information on the pictures to store, then yes,
use a db. Otherwise all the info you need is available from the files.

For small numbers I wouldn't store the filenames in the db. For 20K, I
would.

Decide on how many images per page, then use SELECT with LIMIT to pull
out a page's worth of files and show the page.  Back/Next tell the page
what offset to use for the LIMIT clause.


Niel

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



Re: [PHP-DB] problems with functions/included files/mysql resource

2007-03-27 Thread Niel Archer
Hi,
> 
> In the function to connect to and select the database, I make the mysql-link 
> resource a global value.

It sounds like you've misunderstood 'global' variable.  The global
statement needs to go inside the function where you want to use the
variable, not where you assign it.  This tells that function to access
that variable from the global scope.  You will need to have this
variable available at the global scope.  Creating it inside another
function will not do, you must return that from the function to the
global scope too

e.g.



Niel

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



Re: [PHP-DB] sunrise / sunsite / correcting for summer time

2007-03-25 Thread Niel Archer
Hi, 
  see the docs for the date() function.  'I' returns 0 or 1 indicating
Daylight Saving Time. However, it does this based on the settings for
your installation.  i.e. if your webserver is running on a host
configured to U.S. time zone, it'll give U.S. DST results.

  Note that, any method will only remain accurate until the goal posts
are moved next.  The U.S. for example changed their DST dates last year
(end date moved back).  Australia and other countries have also recently
changed.  In these cases, either your code or the language need to be
updated after such changes.
.
Niel

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



Re: [PHP-DB] Inheritance question

2007-03-19 Thread Niel Archer
Hi

> For example (see below), lets say I would like to use "public $one"  
> property in a new class / method (such as class b)?   What is the  
> best way to accomplish this?  Any help and or suggestions are welcome.
> 
> class a {
>   public $one;
> 
> public function someMethod() {
>   $this->one = '1';
>   }
> }
> 
> class b {
>   public $two
> 
> function someOtherMethod() {
>   $this->two = '2';
>   }
> }

At least two ways you could go about it.  Most straight forward would
 be to inherit, like this:

class a {
public $one;

public function someMethod() {
$this->one = '1';
}
}

class b extends a{
public $two

function someOtherMethod() {
$this->two = '2';
}
}

$object = new b;

$object->someMethod();
$object->someOtherMethod();

print $object->one, $object->two;


In addition to that, if you actually need to use an instance of a
separately to b, you can pass the instance of a into b as a parameter.
Definition for 'b' would need to be something like:

class b {
public $a;
public $two

function __Constructor($dummy) {
$this.a = $dummy;
)

function someOtherMethod() {
$this->two = '2';
}
}

$object1 = new a;
$object2 = new b(&$object1);

$object1->someMethod();
$object2->someOtherMethod();

print $object2->a->one, $object2->two;

There are more than likely other ways to go about this.  Check the
documentation for further examples of how to use classes in PHP.

Niel

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



Re: [PHP-DB] Re: do not display dublicated entries

2007-03-14 Thread Niel Archer
Hi

> I have tried everything except of the one that forms the date in one field 
> and use the DISTINCT for ip and date.

It works for me. I use it for essentially the same job, listing most
recent visit to a location (not IP, but physical venue).

Have you tried adapting it to your needs, such as:
$query = "SELECT DISTINCT ip, day, month, year FROM tracker WHERE page = 
'index'  ORDER 
BY `tracker`.`year` DESC , `tracker`.`month` DESC , `tracker`.`day` DESC LIMIT 
0, 20";


Niel

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



Re: [PHP-DB] do not display dublicated entries

2007-03-13 Thread Niel Archer
Hi

  First, unless there is a compelling reason not to, I'd suggest you use
a single date field, instead of separate year, month, day columns.  It
will be much more efficient on space and indexes.

Then, based on your own query, use:
 SELECT DISTINCT ip, date FROM tracker WHERE page = 'index' ORDER BY
date DESC LIMIT 0,20

Niel

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



Re: [PHP-DB] Urgent! Installing PHP 4 on 64-bit machines

2007-03-07 Thread Niel Archer
Hi

I've only had MySQL 4.1 running on 64 bit windows and PHP 5.x, without
any real problems when used locally.  However, there seemed to be a
problem using the MySQL server via TCP/IP, hence the upgrade to native
64 bit version (v5.0), which was not desired at the time but seemed to
be the only fix we could find.


Niel

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



Re: [PHP-DB] Urgent! Installing PHP 4 on 64-bit machines

2007-03-06 Thread Niel Archer
Hi 

> I need urgent help. Have anyone successfully installed PHP 4 & MySQL 4.0 on 
> 64-bit Windows?

Frankly, why would you want to?  Neither are written for 64 bit.  The
only versions I could find for 64 bit were the 5.x versions in both. 
Which is what I run on my personal computer.

Niel

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



Re: [PHP-DB] csv problem.. read csv from var

2007-02-16 Thread Niel Archer
Hi

sorry, I misunderstood your problem, it was not too clear to me as the
code you list shouldn't produce the output you supplied.

try this:

$array = explode(',', $csv);

print "= " . $array[0] . "\n";
print "= " . $array[1] . "\n";

for ($i = 2; $i < count($array); ++$i) {
 $txt.= "=" . $array[$i] . "\n";
}

print $txt;


Niel

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



Re: [PHP-DB] csv problem.. read csv from var

2007-02-15 Thread Niel Archer
hi

> the problem i have is.. how about the csv is a var
> DATA===
> $csv="
> A507257,3/2/2007,\"Hematologi Lengkap,Cholesterol Total,LDL
> Cholesterol,Trigliserida,HDL Cholesterol,Asam Urat,Gula Darah Puasa,Gula
> Darah 2 Jam PP,Kreatinin,Ureum,Bilirubin Total,Alkali
> Fosfatase,SGOT,SGPT,Urine Lengkap,Feses Rutin,Darah Samar Faeces,VDRL,Anti -
> HBs,Total PSA,HBsAg,Anti - HCV Total\"";
> 
> what should i do to make the ouput like above.

Use 

  $arry = explode(',', $csv);

to separate the variable into an array, then process it using foreach as
before

Niel

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



Re: [PHP-DB] Trying to add primary key to existing database.

2007-02-04 Thread Niel Archer
Hi.

  I don't know cPanel, but I expect it can run SQL directly, most panels
can.  Use the ALTER TABLE ADD {INDEX|KEY} syntax to add indexes/primary
keys.  You can use multiple columns, which together form a unique value
to create your primary key.

Niel

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



Re: [PHP-DB] What effects MySQL connection's character set

2007-01-31 Thread Niel Archer
Hi all

  Finally identified the problem. Was pretty obvious in retrospect.

  The mysqli class (Improved MySQL extension OO style) defaults to
latin1 as a character set, regardless of what PHP is using.  Simple
solution is to use the set_charset method (mysqli_set_charset for non OO) on
the object, which will change the connection parameter.

Niel

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



Re: [PHP-DB] How to tell if a field type is auto_increment

2007-01-30 Thread Niel Archer
Hi John,

I'd suggest searching within the Extra field instead of testing for the
value explicitly, as this field can theoretically hold several extra
pieces of information.

Niel

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



Re: [PHP-DB] What effects MySQL connection's character set

2007-01-30 Thread Niel Archer
Hi

>   Thanks for this. That page didn't actually help, but one of the follow
> ups did.  Apparently, despite being setup as UTF-8 throughout the Db,
> tables, and columns.  The returned data still can default to Latin1.
>   I've forced my test server to return UTF-8 (I hope) and am trying it
> out today. Fingers crossed!

  That turned out to be overly optimistic.  Even Though the server is
using UTF-8 throughout, it still defaults to latin1 on connections.  So
I used the SET NAMES utf8. It still will not work as I expect.  I used
the following code to test it.

$Db = new mysqli($Host, $User, $Pass, $Db);

$Db->query("SET NAMES utf8");
$result = $Db->query("SHOW VARIABLES LIKE 'character\_set\_%'");

$count = $result->num_rows;
while ($count):
$dummy = $result->fetch_assoc();
print $dummy['Variable_name'] . " = " . $dummy['Value'] . "\n";
--$count;
endwhile;

print "\ncharacter_set_name: " . $Db->character_set_name() . "\n";

Which results in the following output:

character_set_client = utf8
character_set_connection = utf8
character_set_database = utf8
character_set_results = utf8
character_set_server = utf8
character_set_system = utf8

character_set_name: latin1

  I can't find any documentation on PHP's character encoding, beyond the
default_charset directive.  Several of the functions/extensions have
documentation, but not PHP itself.
  I suspect the problem is with php itself or the mysqli extension,
which was my original thought and reason for my post.

  Anyone have any ideas?


Niel

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



Re: [PHP-DB] What effects MySQL connection's character set

2007-01-30 Thread Niel Archer
Hi Chris.

  Thanks for this. That page didn't actually help, but one of the follow
ups did.  Apparently, despite being setup as UTF-8 throughout the Db,
tables, and columns.  The returned data still can default to Latin1.
  I've forced my test server to return UTF-8 (I hope) and am trying it
out today. Fingers crossed!

Niel

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



Re: [PHP-DB] How to tell if a field type is auto_increment

2007-01-29 Thread Niel Archer
Hi

Try using:
 SHOW COLUMNS FROM db.table LIKE 'field_name%'

and from the returned row, check the 'Extra' column for 'auto_increment'

Niel

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



Re: [PHP-DB] can u help me in PHP

2007-01-28 Thread Niel Archer
Hi

> I read ur reply on newsreader abou mysqli and if i can use it in PHP4
> 
> My question is where can i find a link to download the mysqli extension
> separately without changing to PHP5

  The MySQLi extension is available before PHP v5, but I couldn't tell
exactly which version it was introduced with.  I'm pretty certain it's
part of 4.1.
  However, this doesn't mean it is enabled.  If I recall correctly, on a
windows platform it is available as a dll, but needs to be enabled in the
php.ini.  With other platforms, I think it needs to be compiled in with
an additional switch.

Niel

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



Re: [PHP-DB] Am I missing something?

2007-01-27 Thread Niel Archer
Hi

> Alright, I did that. I now get :
>  INSERT INTO domains ( picture, thumbnail ) values( '', '')
> 
> and no data entered.

Then for some reason your variables are empty.  Make sure they have data
on entry to the function.  If they don't keep backtracking until you
find where it's lost.

Niel

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



Re: [PHP-DB] Am I missing something?

2007-01-27 Thread Niel Archer
Hi

you need to change this:

> $insert = 'INSERT INTO domains ( picture, thumbnail ) values( "$picture",
> "$thumbnail")';

 to be:
$insert = "INSERT INTO domains ( picture, thumbnail ) values( '$picture',
'$thumbnail')";

variables are only interpreted inside double quoted strings.  Within
single quotes, everything is taken exactly as it appears.


Niel

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



[PHP-DB] What effects MySQL connection's character set

2007-01-26 Thread Niel Archer
Hi all

How is the character set of returned data effected?  I have a DB using
UTF-8 encoding., PHP is set to use UTF-8 internally. However the MySQL
connection returns Latin1 data.  How can I get it to return UTF-8 data
instead.

TIA

Niel

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



Re: [PHP-DB] Formatting MySQL Queries

2007-01-24 Thread Niel Archer
Hi

SELECT * FROM table INTO OUTFILE 'file_name'
  FIELDS TERMINATED BY '\t'
  LINES TERMINATED BY '\n'


Niel

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



Re: [PHP-DB] mysql rereading result set (fetch_assoc)

2007-01-09 Thread Niel Archer
Hi

> Hi, I would ask which way is more efficient and save time? Save each row to
> array or mysql_data_seek(0) ? 


  That totally depends on which resources are more valuable to you.
  The array will likely use more memory but be faster to process. 
  While mysql_data_seek(0) would probably use no additional memory but
be slower. It also might require you to duplicate code.

Niel

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



Re: [PHP-DB] CURL and process not finishing

2007-01-09 Thread Niel Archer
Hi

> leaving me with the question: what does
> max_execution_time relate to?  is it more like a maximum time without 
> activity.

max_execution_time is the time php gets to execute code.  From the
documentation: "The maximum execution time is not affected by system
calls, stream operations etc. Please see the set_time_limit() function
for more details."


Niel

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



  1   2   >