Extremely basic PHP and Mysql - php

Background: I am more of a designer than a programmer, but have hacked templates for many open source CMS's (Drupal, Joomla, Wordpress)
I want to start from scratch in regards to the relations of php and a mysql database.
Lets assume I have a working database and php engine locally.
What would be my first step to connecting to my database and creating a table... (im happy to be led to an appropriate tutorial...)
Many of the tutorials I have seen start with basic php, but I would rather explore the connection between the db and the php.

This seems to be a pretty good tutorial:
http://www.freewebmasterhelp.com/tutorials/phpmysql

W3Schools has a big tutorial on both PHP and MySQL.
A useful tip is also to know that you can look up anything you need on the official PHP and MySQL support pages by going to
php.net/search-term-here (example)
mysql.com/search-term-here (example)

If you want to really get a leg up... see if you can get programs like CPanel and PHPMyAdmin.
PHPMyAdmin will give you a more familiar UI for database control and ease you into using mySQL.

There are two ways: start to learn SQL and create tables trough SQL or use PHPMyAdmin to administer the database. From then on you only have to learn how to get the data from the database.
PhpMyAdmin also displays the queries so you can analyze these.

Get into PDO . It's gonna be the next big php/mysql thing. A lot of sites have switched to it. It's simple and securer than conventional mysql_* . A good book (for beginners and to start you going) that is for sure not for production is Wicked Cool Php Scripts

You can also have a look at XAMPP, which makes installing everything required for PHP/MySQL a breeze. Linux, Windows? No problem.

Nettuts and theme forest blog have a nice video series on learning php. They have other series such as wordpress and are currently doing a series on code ignitor which both use php.

Install mySQL and look up basic tutorials on how to create a table, update, etc. Once you feel handy with that, install XAMPP lite, where you can start practicing PHP. Look up tutorials on how to use PHP to access your database. XAMPP also has phpMyAdmin, so you have a much easier interface to work with your databases.
It'd be good if you had some basic programming knowledge too-- it makes understanding PHP significantly easier.

This is an example on how you connect php to your database:
<?php
$dbh = new PDO('mysql:host=localhost;dbname=test', 'root', '');
?>
mysql = database driver
host = localhost or 127.0.0.1
dbname = your database name
'root' = your database username
'' = database password
*Visit and explore this link for more info about PHP with Database.

Related

Migrate PHP code from MSSQL to MySQL[duplicated]

I currently have a large web application that connects to MSSQL to fetch its data. This web app has hundreds of .php files. I have a new customer, and he doesn't want to use MSSQL, but MySQL instead.
I've searched and found lots of articles on how to migrate data. But that's not my problem. I know how to do that, besides we'll be starting with a blank database, except for a few default catalogs.
Any help greatly appreciated

Using a .sql file in Database manipulation with PHP

I am kinda new to the whole development side, but I want to be good.
In database creation, I used to do this via PHPMyAdmin --> Wamp Server.
I got to learn how to use MySQL Workbench, and I am liking the experience.
The problem is, when I have the .sql file created via use of Work Bench, e.g. data.sql, I cannot import it to PHPMyAdmin, so as to continue in a my developments (web-related) as there are many errors comming up e.g. #1146.
It is really frustrating since I have to do double work and create what I did in Work Bench in PHP MyAdmin.
Is there a simpler way?
Like can I just connect to a .sql file (as the database) and continue with execution of my projects? (Its a bit stupid, but I have been reduced to that.)
Please help.
Thanks in advance.
This post seems like it might help you out, did you check the default encoding of the dump and make sure mysql expects the right type of encoding?
http://forums.mysql.com/read.php?103,275798,275798
Also: Please read the policies of the board before asking your question. It states to do some research before asking questions like this... I googled "mysql workbench dump to phpmyadmin" and the very first item that popped up was a video explaining this EXACT situation. :)

Running PHP on iOS?

I have an app that uses a few php scripts to access a mysql database.
Can anyone advise on how to implement an offline version?
I understand it is easy to create an SQLLite database in the app and populate it when the web server is available? true?
When I want to query it, is it possible to do that using the pre-existing php?
thanks in advance
HMJ
It's important that you make the distinction between the components you are speaking of - PHP is a server side language that is meant to carry out the DB queries. SQLite is the iOS framework that allows us client-side DB management on the iOS operating system. On the iPhone you can carry out the same queries that are generated using your PHP but they are to be built using objective-c. There are some useful wrappers that do this, including FMDB.
Kodiak PHP runs on an iPad. It has PDO installed. You can create a local sqlite database. I tested it with this code:
<?php
error_reporting(E_ALL);
$db = new PDO('sqlite:test.sql');
$n = $db->exec('DROP TABLE IF EXISTS USER');
$n = $db->exec('CREATE TABLE user (login TEXT)');
$n = $db->exec('INSERT INTO user VALUES("joe")');
$r = $db->query('SELECT * FROM user');
foreach ($r as $row) {
echo $row['login']."\n";
}
?>
In regard to PH7... it just implements the PHP language and a some functions, it does not support all PHP functions nor extensions. For instance, PCRE is often used for regular expression processing. PH7 does support it. PH7 is a rewrite, intended for embedded applications, basically a more capable scripting engine such as Lua, but not as big a footprint as Javascript.
Kodiak PHP is an actual PHP port. Use phpinfo(); to see what is has compiled into it, it's quite a bit.
To run your SQL scripts in an iOS app, you'll need to compile a PHP engine into your iOS app and get Apple to allow it :) - Kodiak is able to do it because Apple allows exporting files written in their app, but Apple does not allow importing files into the app. Therefore, you must use copy/paste. The app is intended for writing and testing code not running a bunch of PHP script to create an app.
In short, the answer to your question is: Yes, it is possible to run PHP and write to an sqlite database in an iOS app. However, to do so you'll need to compile a PHP library into your app. Compiling PHP for iOS is no small feat (I haven't done it yet). Kodiak has done it, but I have not found a freely available PHP library for iOS yet.
I don't think you can "install" php on iOS. But, you may also, I can't tell.
What I would do, easier I think, is to create a local database with the same schema and stuff.
If offline, pull from the offline DB, online from the live DB (web).
How to ?
Write a script that will play the role of "Model". It's like in the MVC technic. Your script will only need to handle both DB. Since SQL is SQL, your queries will not really change so :
if(Offline){
// Offline
Use something similair to PDO but for SQLLite
} else {
// Online
Use something similair to PDO but for MySQL
}

How to access an SQLite database file stored on cd using php?

I have a small mySQL database and a few simple php based webpages that query the database, generate html tables and present them in the browser. The database is no longer being updated. So, searching and viewing subsets of the data is all that is required.
Some users are interested in distributing the searchable database on a cd or usb memory stick. SQLite seems to offer the answer, but I don't understand what is needed to make this work. What will be required to make a web browser based "app" work from a memory stick in the absence of a server like xampp?
XAMPP Lite from http://portableapps.com/apps/development/xampp
What you want is called a "standalone server". This is very common in almost every other modern language except PHP, for some reason. Googling "standalone php server" reveals several options:
QuickPHP
Nanoweb
Server2Go

SQL Compact database with PHP

I have been given 2 files .DB and .sdf to work with. I have googled it a little and found out that its SQL Compact database format. I really have no idea how to work with these database files.
I have found here on stackoverflow some 3rd party tools, bud they were all for windows (I am on Mac).
I have also tried to open it in SQLite but no success.
I need this data in my web app written in PHP. So conversion to MySQL or Postrge seems to be an ideal solution. Any ideas?
You can use MSSQL extension in PHP to work with these databases

Categories