Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> MySQL & PHP coding
Rating 4 V
spyshow
post Sep 19 2004, 08:18 PM
Post #1


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 10
Joined: 18-September 04
Member No.: 709



So it seems as though the php docs make it very clear that mysql and mysqli functions will all connect to the database as a latin1 client. Although i have my server set up with utf8 databases, tables and fields and the default client connection is utf8, php still connects as latin1.

My xhtml forms and pages are all utf-8, so when i post utf8 data and insert it into the database the connection assumes that incoming data is latin1 and the data that gets placed in the database is invalid.

phpMyAdmin seems to be able to view, add, edit, and retrieve utf8 strings in the database just fine using my current installation of php. How?

Does anyone know how to make sure that the complete workflow is entirely utf-8?
Go to the top of the page
 
+Quote Post
hbs_25
post Jan 10 2006, 04:56 PM
Post #2


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 4
Joined: 9-January 06
Member No.: 10,603



Try to use this function mysqli_real_escape_string. Seems to work with PHP 5 and maybe could correct the problem. For more info, check this link

http://br.php.net/manual/pt_BR/function.my...cape-string.php
Go to the top of the page
 
+Quote Post
TavoxPeru
post Apr 10 2006, 07:55 PM
Post #3


Super Member
Group Icon

Group: [HOSTED]
Posts: 763
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



hi, thats a common problem with no english data, and for that reason a time ago i create this function no manage that problem:
CODE
function SafeEscapeData($strData)
{
    if (get_magic_quotes_gpc()) {
        return $strData;
    }
    else {
        return mysql_real_escape_string($strData);
    }
}


for php5 use this function mysqli_real_escape_string.

hope it will help you.

best regards,
Go to the top of the page
 
+Quote Post
Ben Devos
post May 30 2006, 07:43 AM
Post #4


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 1
Joined: 30-May 06
Member No.: 13,726



Here is an example:

CODE
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
   printf("Connect failed: %s\n", mysqli_connect_error());
   exit();
}

$mysqli->query("CREATE TEMPORARY TABLE myCity LIKE City");

$city = "'s Hertogenbosch";

/* this query will fail, cause we didn't escape $city */
if (!$mysqli->query("INSERT into myCity (Name) VALUES ('$city')")) {
   printf("Error: %s\n", $mysqli->sqlstate);
}

$city = $mysqli->real_escape_string($city);

/* this query with escaped $city will work */
if ($mysqli->query("INSERT into myCity (Name) VALUES ('$city')")) {
   printf("%d Row inserted.\n", $mysqli->affected_rows);
}

$mysqli->close();
?>


Greets

Wtfox
Go to the top of the page
 
+Quote Post
Quatrux
post May 30 2006, 08:08 AM
Post #5


the Q
Group Icon

Group: [HOSTED]
Posts: 1,051
Joined: 13-July 05
From: Lithuania, Vilnius
Member No.: 7,059



I don't know if this will help, but don't you have to do a mysql query to set utf-8 ? with SET names utf8 ? so you need in your php script to write a query before anything you post/get from the database..

mysql_query("SET names utf8");

I never done it before, but this is what I know theoretically, hope it helps wink.gif or maybe I didn't get your problem.
Go to the top of the page
 
+Quote Post
HeLLRaiSer
post Jun 25 2006, 07:40 PM
Post #6


Member [ Level 1 ]
Group Icon

Group: Members
Posts: 47
Joined: 24-June 06
Member No.: 14,107



hello there.. does anyone know PHP? or any learning tutorial?
i want to learn PHP?
i want to know how to design webpages on PHP?
please help me out smile.gif
Go to the top of the page
 
+Quote Post
Houdini
post Jun 25 2006, 08:49 PM
Post #7


Super Member
Group Icon

Group: Members
Posts: 572
Joined: 25-April 05
From: Nashville Tennessee
Member No.: 4,340



Well a good FREE online resource for those that are beginning to learn PHP is called Practical PHP Programming. It is up to date and includes PHP 5. I use it when I am indoubt about certain PHP features. I would suggest though that if you want to learn PHP and MySQL you will need a operatin server on your machine. XAMPP or WAMP or if you have a Mac then MAMP all will create and install a webserver with PHP and MySQL and with XAMPP you get Perl and also the ability to switch between PHP 5 and PHP 4.
Go to the top of the page
 
+Quote Post
HeLLRaiSer
post Jun 25 2006, 09:17 PM
Post #8


Member [ Level 1 ]
Group Icon

Group: Members
Posts: 47
Joined: 24-June 06
Member No.: 14,107



QUOTE(Houdini @ Jun 26 2006, 01:49 AM) *

Well a good FREE online resource for those that are beginning to learn PHP is called Practical PHP Programming. It is up to date and includes PHP 5. I use it when I am indoubt about certain PHP features. I would suggest though that if you want to learn PHP and MySQL you will need a operatin server on your machine. XAMPP or WAMP or if you have a Mac then MAMP all will create and install a webserver with PHP and MySQL and with XAMPP you get Perl and also the ability to switch between PHP 5 and PHP 4.


I have Visited that website its pretty good and very informative
thanks alot
Go to the top of the page
 
+Quote Post
TavoxPeru
post Jun 25 2006, 09:54 PM
Post #9


Super Member
Group Icon

Group: [HOSTED]
Posts: 763
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



QUOTE(HeLLRaiSer @ Jun 25 2006, 02:40 PM) *

hello there.. does anyone know PHP? or any learning tutorial?
i want to learn PHP?
i want to know how to design webpages on PHP?
please help me out smile.gif

Hi, you have a lot of good websites to learn php. I recomend you to first download php from the oficial website: PHP Download Page, then read the simple tutorial here: PHP: A simple tutorial and finally i suggest to download the official php help file: PHP Documentation.

BTW, dont forget to visit frecuently this forum you will find a lot of good examples and many people that can help you wink.gif .

Best regards,
Go to the top of the page
 
+Quote Post
vujsa
post Jun 26 2006, 01:14 AM
Post #10


Absolute Newbie
Group Icon

Group: Admin
Posts: 888
Joined: 20-February 05
From: Indianapolis, Indiana, USA (Midwest)
Member No.: 2,714



QUOTE(HeLLRaiSer @ Jun 25 2006, 03:40 PM) *

hello there.. does anyone know PHP? or any learning tutorial?
i want to learn PHP?
i want to know how to design webpages on PHP?
please help me out smile.gif

Well, you happen to be in just the right place. We have a lot of people here that know PHP pretty well.

There are a lot of tutorials on the subject of PHP in the tutorials section. The PHP section can be found here: http://www.astahost.com/php-f86.html

I personally have written a few of the tutorials in that section and I think of those the easiest to learn from is this one: http://www.astahost.com/rapid-html-code-ge...-php-t2969.html It seems to be the most relevent to your request since it deals directly with HTML code generation.

The next one that might interest you is the one I wrote about basic template websites using PHP. http://www.astahost.com/cms101-content-man...sign-t7778.html This wil give you a basic idea of how to maintain a website using the PHP include() funtion which will allow you to store various elements of your website in various folders that can be use for every page or only one page depending on the files contents. Basically, you can use this to modify a single file instead of every webpage you have if you want tomake the same change on all of your website.

These are the two most basic yet practical tutorials that I know of. They should give you a decent place to start learning from. I could teach you the "Hello World!" script but it isn't very practical.

I think you should consider getting a decent beginners book on the subject. I wouldn't worry too much about getting a PHP5 book since there isn't really that big of a difference for a new user and you'll need to learn PHP4 for current compatibility. PHP4 scripts will work on a PHP5 server but there are additions to PHP5 that make PHP4 servers unable to run all PHP5 scripts. You can get a decent used book on the subject for less than $10.00US.

My first PHP book was "PHP Fast&Easy Web Developement" by Julie C. Meloni ISBN:1-931841-87-X
It was a very good beginner book that explained the use of basic PHP and how to use PHP with MySQL. Additionally, it showed how to set up a Apache based PHP and MySQL web server for home testing.

The same author has a new verion of the book out entitled "PHP 5 Fast&Easy Web Developement".

I would suggest that you only visit the PHP website after you get a basic understanding of PHP. The PHP website is not a how to website but instead offers a reference of functions and syntax that can be used for PHP scripts. Without some idea of what the various functions do or how to use the syntax in it's most basic form, the PHP manual will only server to confuse and frustrate you. Most PHP scripters use the manual as a quick reference when they forget the proper use of a function or what options a function has built into it.

Finally, come up with a task that you want to complete with PHP and attempt to write the code required to perform that task. When you reach a point at which you don't know how to continue, post the code and you problem here. Someone will help you through the rest of the code as you need. If you don't understand the response or you are unclear as to what you should do with the repose, be sure to reply and ask for clarification. Many times the person offering help doesn't know your level of knowledge in PHP and may assume that you know some important piece of information needed to make the solution work.

Outside of that, just keep working at it. Do a little script here and another one there. Maybe combine a couple of scripts until you get enough pieces of code together to have an application of some type. Ususally, the easiest way is to write a large script is to write several smal scripts that work together.

Hope This Helps! cool.gif

vujsa
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Need Help With A PHP - MySQL Registration Script(13)
  2. Coding A Private Message System(4)
  3. Need For PHP/MySQL Creator(1)
  4. Printing Out A Table(6)
  5. Need Some Help Using PHP & MySQL(4)
  6. [PHP + MySQL] Separating The Results By Pages(0)
  7. [PHP + MySQL] Encrypting Data(11)
  8. [php] Index.php?section=xx&pag=yy(6)
  9. How Do You Create A Secure Loging?(4)
  10. Important: Basics Of Using PHP And MySQL(10)
  11. Need Help With Php/mysql And Web Servers Such As Asta's.(4)
  12. PHP Coding Help!(5)
  13. Need MySQL Alternative To The Syntax "or die()"(8)
  14. Re-order MySQL Table(11)
  15. PHP & MySQL: Displaying Content From A Given ID(6)
  1. How To Show Serial Nums In PHP Table For Contents Of MySQL DB(4)
  2. Php Mysql Errors(2)
  3. Sql Injection Prevention (passing Numerical Data Across Pages).(9)
  4. Php/mysql And Manual Page Caching?(4)
  5. Too Many Connections?(4)
  6. Extracting Mysql Maths Using Php(2)
  7. Anyone Know Of A Really Good Mysql Class?(4)
  8. Warning: Mysql_num_rows()(1)
  9. Warning: Mysql_result(): Supplied Argument Is Not A Valid Mysql Result Resource In ...(4)
  10. Making A Link = Mysql_query(8)
  11. Making Something In Mysql Happen Only Once(10)
  12. Mysql Question(inserting Number From A Textfield)(3)
  13. Letting Users Add Mysql Data With Php(1)


 



- Lo-Fi Version Time is now: 10th October 2008 - 07:58 PM