Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I was developing a website and learning how to code at the same time. So far I just got the hang of PHP. And now i want to learn how to integrate databases with PHP. Do i start learning MySQL and its libraries? I've been reading that PDO are the way to go and I'm just lost on what order I should be learning things.
Mysql is a database. Completely different thing. One is supposed to learn basic Mysql separately, independently from PHP or any other language, practicing basic queries in console or whatever GUI client.
Once you make yourself familiar with basic SQL, you can turn to running basic queries from PHP using PDO. Only static queries without variable parts.
And finally, you may start for building dynamical queries using prepared statements. Basic info on PDO you can find here in the tag wiki
You have a very open-ended question.
However, typically with PHP the standard is MySQL so I would suggest you learn that. Furthermore, most SQL is similar in syntax. Typically when working in PHP you will use MySQL, PostgreSql or SQLlight. They all have very similar syntax.
I suggest you find a book on PHP/MySQL and study that. I typically don't endorse books, but there is a great book for beginners by Head First called, "Head First PHP & MySQL". You will learn a lot with that book, you can google it as I don't know the link.
Furthermore, php.net is your best resource for PHP-related programming.
One final tip, I suggest you learn the Object-oriented way to program in general including opening your database connection as procedural-style is going away.
Good luck! And I am happy you are going with PHP and aren't another .net drone.
(also, download cake.php or codeignighter to learn about building lightweight, well-designed frameworks)
I would start in following order:
Create basic table and input some value through phpmyadmin
example: do one for users. create table named "user" and columns "user_id","username","password", "email"
Use SELECT statements to select certain data through phpmyadmin
Build simple php page with connection and retrieve your db data
Learn about SQL injections and security issues learn Object Oriented Programming for PDO use (optional)
Start transferring your traditional mysql into PDO type
and then start learning mysql more in depth
Good Luck!
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I wanted to ask that if and how is it possible to make a PHP-based application independent of the SQL engine used?
(Under that I mean that the application can be executed on PostgreSQL, MySQL and maybe also Oracle SQL.)
Current idea is to leave the PDO DSN into the config file, so that the queries etc everything else stay the same, but can I face some problems in regards of CRUD actions to the tables themselves?
If I don't add any complex stuff in it, then is it possible for me to make it so that it doesn't depend on the engine at all, only has the PDO DSN for the database and that it can query everything the same way on each of the SQL engines?
Best regards!
Read about Database Abstraction Layer. There are quite some libraries available for PHP. If you choose any of the popular frameworks, to mention Symfony or Laravel - you will have the DBAL out of the box - either Doctrine or Eloquent. Both offer similar query building functionality, IMO based on HQL.
Definitely don't try to write it "your way". Even if you do only simple queries the gramma is different, to mention just the types, incrementing etc...
If you stick to a common subset of SQL which is supported by all your targeted databases, then yes, you can get away with using the same PDO instance, the same queries, and just switching the PDO DSN.
Practically speaking however, for anything but the most trivial queries, you'll probably be using some database specific features which you'll have to implement slightly differently for different databases. Simply speaking that means your code will have to execute query A if connected to MySQL but a slightly different query B if connected to Postgres.
You certainly do not want to implement that using a lot of if..else, instead you want to be using database specific adapters/drivers. In your business code you'll be calling $database->getUserRecords(), and depending on whether $database uses the MySQL or Postgres adapter the query will be slightly different. (Also see dependency injection.)
You can either do this by implementing those adapters by hand and tweaking the queries for each database, or use a more abstracted ORM/DBAL which can assemble the correct query on the fly using database-specific query builders. There are many existing libraries for that.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm making a website for a group that needs a database. The data is going to store user information among other things. I already know PHP and could easily do it in PHP, but to further myself as a developer, I'd like to learn a language like Ruby. I know how to use databases in PHP. But, when writing Ruby, can I use SQL databases?
We don't know how you call your database in PHP.
Many PHP users use MySQL and call sql statements with the embedded mysql driver,
and then iterate over the results.
You can do this also in Ruby. The mysql driver is not embedded, But you can easily install it with RubyGems. You need the mysql2 gem.
https://github.com/brianmario/mysql2
But if want to be more object-oriented, there is the framework "Ruby On Rails" with "ActiveRecord" for database connection. Here you don't write SQL directly, instead you specify what objects you want to have or store (except in rare edge cases, where you still can write sql)
This needs some learning time. But then it is lot less coding, code is better readable, and security errors like are also easier to avoid.
The basic answer is yes - you can do something like that using Ruby and a framework like ActiveRecord or Sequel, but this far too broad for StackOverflow.
Good afternoon.
Depends on the speed you need .
1) If you need quickly - write on PHP
2) If you have some time and want learn Ruby On Rails, ActiveRecord etc. ... buy some book for beginner, read doc and step by step create application
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm a proficient programmer, and I can write PHP code without any trouble, but, I run away from MySQL, in my own projects, I use the excellent RedBean object mapper, but, for freelance projects, I have to learn MySQL, and its calls from PHP, what books what you guys recommend?
It would be great if the book suggested is available on Flipkart
I found Luke Welling's PHP and MySQL Web Development to have a good overview of the MySql functions in PHP. The aforementioned Learning PHP, MySQL, and JavaScript is excellent as well.
I found Learning PHP, MySQL, and JavaScript to be helpful, but it sounds like you are well beyond that. In that case take a look at Web Database Applications with PHP and MySQL. Both are from O'Reilly.
And once you get familiarized with basic MySQL queries, you might be excited to jump ahead and learn about some performance reading: High Performance MySQL and MySQL Performance Blog offer a lot of knowledge. Freelance projects that become popular often need database tuning.
Basic things you can read in Zend PHP5 Certification Study Guide.
And for more advanced usage Expert PHP and MySQL
Nothing's better than the PHP and MySQL documentation.
I will recommend referring the PHP manual to learn how to connect to MySQL and execute queries and read results from PHP - http://php.net/manual/en/book.mysql.php
The MySQL manual itself very efficiently explains the subject - its mainly the following query types that you'll be mostly looking for:
CREATE TABLE
ALTER TABLE
INSERT
SELECT
UPDATE
DELETE
Refer to chapters 10, 11 and 12 to get started - http://dev.mysql.com/doc/refman/5.5/en/.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Is there a known good reporting library? Before I go making my own, I was wondering if anyone who has come up with a solution I can adapt to? Basically, I have a bunch of MySQL queries that I need to "report" on. So, my in-house solution would basically be a bunch of mysql queries that need to be run through a drop down or reporting style menu and they would run the queries requested and build a little report of whatever sql query that was run. Is there something out there that already does THIS, or should I just build something in-house?
Take a look at phpreports. It sounds like what you are looking for.
Pentaho Reporting, Jasper Reports, or Eclipse BIRT can all work with MySQL. I haven't seen any PHP based reporting libraries out there. So, you can just set up one of those applications and have it communicate with your database to allow for reporting.
If you are just looking build table output from MySQL statments, try this example from jqGrid: http://www.trirand.com/blog/phpjqgrid/examples/loading_data/array_data/default.php#PHPCode
Please take a look at Windward Reports. With Windward you design the reports in Microsoft Word, Excel, or PowerPoint - so no learning curve and you can design reports that Crystal, SSRS, etc. can't even dream about. (Disclaimier - I'm the CTO at Windward.)
We have a large number of customers who use MySql for the datasource. And we have a PHP wrapper to call our Java engine.
thanks - dave
If you want something simple but effective try my PHP MySQL Reporter Script - https://jellyhound.co.uk/mysql-email-reports/ - it's extremely basic but very effective, I've had over 500 sales and pages of feedback and questions.
UPDATE: THIS IS NOW FREE
It is packaged as a simple way to generate MYSQL reports by email but is used as an effective report generator by a lot of my users.
It includes CSV and PDF attachments and can easily be scheduled using cron or any operating systems scheduling software.
I use two reporting engines for converting SQL quires to reports, I think any of them could meet your needs :
Smart Report maker : this one supports creating MySQL reports based on SQL quires , views, and tables
MYDBR : This one supports building reports based on stored procedures
I was going to vote to close this as an exact duplicate of a question which has been asked many,many times here. But the previous answers are not great.
Christopher's answer mentions 4 good products. I'd also suggest looking at Agata, phplens, Crystal reports.
I'm surprised nobody has mentioned MSAccess - it has a lot of nice functionality for developing reports, but, IME, managing the software is a major PITA, and there's little scope for scheduling / integration.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I would like to know some good resources (book or website) on learning PHP for those who are already familiar with programming.
Many of the tutorials I've been finding are for people who never programmed before and take way to long to go through to even learn basic language constructs.
The optimal resource would not assume previous web-development background however.
The PHP Manual is what I used, especially with the search box in Firefox. Type in a function name and go. If you haven't already, it's probably worth browsing through while you wait for more answers.
Learning raw PHP is probably the wrong way to go if you're already an experienced programmer. I'd recommend picking up one of the frameworks, such as PHP Cake, Code Ignitor or Symfony. These frameworks attempt to enforce the set of best-practices that have developed for PHP developers over the past six or seven years.
To that end, Symfony has a great, "24 hours" style tutorial that can get you up and running with their framework, which will sneakily expose you to writing PHP code. Even if you decide you don't like symfony, concepts such as MVC, routing, templating, ORM, etc. will be covered. The other frameworks have similar tutorials, but I like the 24, one hour lessons approach.
For questions on specific PHP core functions/classes, php.net serves as a good resource (although the document of some of the core helper classes like XMLReader and the Reflection hierarchy can be sparse).
This site has some good stuff:
http://tizag.com
Whenever I am teaching anybody stuff I tell them to just Google "php [insert what you want to do]" and it will usually be in the first few results.
Another option:
http://php.net
Use http://www.w3schools.com. They've got a great tutorial for beginning and intermediate php programmers. Also, the PHP Manual is fantastic.
I definitely use the official site at php.net and O'Reilly's PHP Cookbook most often.
As well, the zend development zone, http://devzone.zend.com/public/view and
Manning's PHP in Action book are useful resources.
It's a bit old now, but I had a great learning experience with The PHP Anthology. If you check it out, please remember that it was published about 5 years ago.
A quick 'net search reveals there's a new one on the market as well, but I don't have experience with it.
Some free PHP5 e-books.
Practical PHP Programming
PHP 5 Objects, Patterns, and Practice
sounds nice
I strongly agree with #stalepretzel -- the w3schools and php.net sites are both incredibly rich resources for both getting you started and keeping you going.
For video tutorials (screencasts), you really can't beat "In the Woods - Diving into PHP" -- The first video is here: http://blog.themeforest.net/screencasts/diving-into-php-video-series/
Handy dandy quick ref here: http://www.addedbytes.com/cheat-sheets/php-cheat-sheet/
When/if you get stuck on a specific problem you can always come back here to SO.
Nicholas
What is your opinion about w3schools ? I recommend this website. This is suitable for beginners and advanced level too.
Also i would like to refer official PHP website and You Tube(Search Video related to PHP)